I ran the following simple program 10 minutes ago and it worked as expected, i.e. it took input "monster" which contained spaces. But few minutes later I copied the program exactly the same to save as a new program, and it doesn't take the spaces in "monster" input any more--if the input for monster is "John Doe", then it's displayed as only "J". What's happening? I even restarted my computer and still doesn't fix it! Exactly this program:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string monster;
cout << "Enter monster: ";
getline(cin, monster);
cout << "You entered: " << monster << endl;
cin.get();
return 0;
}
Update: Well, I retyped the exact same program again, saved as yet another new file name, and this time it worked! The previous program (exactly the same statements) still doesn't work! What's going on??? So strange!