I have a problem using cin and getline:
This requires the user to hit enter twice. It seems that there is some buffer storing one string and getline retrieves only what is pushed out of the buffer. This is because if I do aCode:string str;
getline(cin, str);
cin.putback('\n');
first, the user needs to hit enter only once after his input, but the retrieved string is only the \n I pushed to the input buffer. Likewise, when I do
the program first asks for a string. Then it waits two times for input ( the user will probably just hit enter ), then output the first line, then ask for another string. While this time the user needs only input one string, the program will then output not this string, but rather the second one from the first getline call.Code:string str;
cout << "Enter a string:" << endl;
getline(cin, str);
cout << str << endl;
cout << "Enter another string:" << endl;
getline(cin, str);
cout << str << endl;
Any ideas how to solve this?
