Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to just dump the remaining input stream?

Status
Not open for further replies.

Sen7inel

IS-IT--Management
Feb 14, 2001
90
FI
-lo,

I'm trying to learn C++..

What if I have

cin.getline(buf, 50);

and the user spams 50+n letters before hitting newline? The first 50 go to buf, and the others just stay in the stream? If this is the case, how can I just clear the stream once and for all, ready for next getline?

I tried some things with cin.ignore, but didn't get it to work.
 
Just use std::string and forget about the buffer..

Code:
std::string input;
cout << &quot;Enter a string: &quot;;
getline(cin, input);
 
you might also try to use the fucntion &quot;flush&quot; to flush the buffer before calling your next &quot;getline&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top