Say you have this
cin >> char a;
cin >> char b;
If you typed in 12 it wouldn't stop at the second cin. This can get annoying because if someone typed 123 it might not only bypass that but go back to somewhere else and enter in a value you didn't want in the first place.
Is there a way to empty out cin? (Meh, I don't know how to phrase it)
Real quick simple question
Moderator: Coders of Rage
Re: Real quick simple question
I'm lost, anyone else know....
Re: Real quick simple question
just build a data validation functions that make sure the user enters the right thing.
Some person, "I have a black belt in karate"
Dad, "Yea well I have a fan belt in street fighting"
Dad, "Yea well I have a fan belt in street fighting"
Re: Real quick simple question
I did that. I have a tic tac toe function. It make sure it's 1 2 or 3, but, when it returns to the previous function it has a option to exit out. It's 2. So if a person did enter 222 (2, 2 is the position) the 2 will carry over to the previous function and enter it to exit the program.
- MarauderIIC
- Respected Programmer
- Posts: 3406
- Joined: Sat Jul 10, 2004 3:05 pm
- Location: Maryland, USA
Re: Real quick simple question
Is there a way to empty out cin?
http://www.cplusplus.com/reference/iostream/istream/sync.html wrote:int sync ( );
Synchronize input buffer with source of characters
Synchronizes the buffer associated with the stream to its controlled input sequence. This effectively means that the unread characters in the buffer are discarded.
Code: Select all
char a;
cin >> a;
cin.sync();
Or a not as good way to do it
Code: Select all
#include <string>
using namespace std;
string dummy;
getline(cin, dummy);
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
- MadPumpkin
- Chaos Rift Maniac
- Posts: 484
- Joined: Fri Feb 13, 2009 4:48 pm
- Current Project: Octopia
- Favorite Gaming Platforms: PS1-3, Genesis, Dreamcast, SNES, PC
- Programming Language of Choice: C/++,Java,Py,LUA,XML
- Location: C:\\United States of America\Utah\West Valley City\Neighborhood\House\Computer Desk
Re: Real quick simple question
Mar's, "Not as good way to do it" is the way i use for everything, so that one looks good to me lol
While Jesus equipped with angels, the Devil's equipped with cops
For God so loved the world that he blessed the thugs with rock
For God so loved the world that he blessed the thugs with rock