Advertisement

simple c++ problem

Started by November 17, 2000 10:13 PM
2 comments, last by rogerh26 24 years, 1 month ago
hey everyone...ya know how if you do a bunch of cins in a row how the enter from the previous one can be held and used in the next one? i know thats kinda vague, but thats the only way i can say it..anyway, how do you clear the buffer or whatever so input statements after the cins dont get screwed up?? suggestions?
i don''t know what you''re talking about but look up "flush"
We are here just like this,It really doesn't matter why.The world is here like it is,'We could laugh we could cry.Is it good or is it bad,Wright or maybe wrong?There's no use of being sad,Without a purpose within a song.
Advertisement
After a cin use the ignore member function that is a part of cin. Like if you only need the user to enter a single number or char or something, you would say cin >> character; cin.ignore(). That would dump every thing else the user typed in, like if they typed in 2 chars. It would delete that 2nd one and keep the 1st one of course. If you want the user to enter in no more than say 10 chars then you would do this. cin >> characters; cin.ignore( 10, ''\n'' ); If that is not what you need, try using cin >> flush. I think thats how you do it.

-Snyper
=============================Where's the 'any' key?=============================
I''m not sure what compiler you are using. But when I was in high school we used Turbo C++ 3.0 for DOS and this is what we used.

  void ClearBuffer(){   apstring Dummy;   getline(cin,Dummy);}  


Maybe that will help. Maybe not. I tried.

This topic is closed to new replies.

Advertisement