|
Answer» Hi,
Im trying to read in a string that contains spaces and for some reason it doesnt PAUSE for me to input. im using Visual Studio 2010 and my GETLINE is:
string tempMessage
getline(cin, tempMessage);
any IDEAS would be great.
Thanks, KhasDo you have any code above this code that USES
cin >> somevar
if you use "cin >>" and that input contains a newline then getline won't stop, because cin >> leaves the newline in the input stream, which is the FIRST thing the getline will see when it gets called.
To fix this, before calling getline use
Code: [Select]cin.ignore(); http://www.cplusplus.com/reference/iostream/istream/ignore/
That works perfectly,
Thank you soooo much
|