String getline() problem
I've written the following code in order to get user input until the user writes a character previously entered:
string str, temp;
cout << "Insert the character that ends the input:" << endl;
cin >> c;
cout << "Insert the string:" << endl;
getline(cin, str, c);
Now, why doesn't the input end if I write the following?
Insert the character that ends the input:
Insert the string:
This is one of the hazards of mixing the extraction operator>> with getline() the extraction operator doesn't extract the end of line character so you will need to remove that character.
Topic archived. No new replies allowed.