• 12
• 27
• 9
• 9
• 20

Help with the Standard Input/Output Streams in C++

This topic is 3405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hello, I haven't used C++ in quite awhile, but for an assignment I was asked to use it again. This program has alot of text input and output. I'm seeming to have trouble using cin to get a string with spaces in it.
string s;
getline(cin, s);

This works fine at the top of my program, but after i use cout/cin a couple times or whatever, the program just skips over these lines, not stopping and allowing user input. I'm not sure the cause of this. I've tried things like,
cout.flush();
cin.clear();
cout.clear();

right before the call to getline, but that doesn't help, program still just skips over it. Can someone give me some insight to why this happens? and possibly what I should be doing to get the desired results? Thanks, ArchG

Share on other sites
cin >> i;getline(cin, s);