Hi, I am trying to read two string, one after another, and before I read the second one I clean the buffer using cout.flush(), but I don't know why the program does not read the second string, not even the the third value using cin, Please I need your help. . . . . . this is the program:
#include<stdio.h>
#include <cctype>
#include <iostream>
#include <string>
using std::string;
using namespace std;
int main(){
int x;
string a,b;
cout << "Enter your first name: " << endl;
cout.flush();
getline(cin,a);
cout << "Enter your surname: " << endl;
cout.flush();
getline(cin,b);
cout << "Enter your age: " << endl;
cout.flush();
cin >> x;
return 0;
}
Thanks for your help. . . . . . .