system("pause")
command to pause the console, since I understand that it conjures demons, and will get me kicked out of a job interview.
|
|
|
|
system("pause")
is that it allows the user to input some characters in a place where I really just want them to press enter. If that's all there was to it, I could live with that. The problem is that this is messing with the other input functions of the program, such as:
|
|
|
|
|
|
|
|
|
|
try this:
|
|
|
cin.get();
or getchar();
to pause the application, but if you do, you should probably use cin.sync();
before taking any actual input from the user.
cin.ignore(...)
is the correct way to do what you are asking. If it isn't working right for you it is because you are not reading input correctly.cin >> foo
typically throws a wrench in the proper understanding of user input.getline( cin, s )
and parse it after that. This makes sure things are properly synchronized.cin.sync()
is useless. Don't bother with it -- it won't help you.Using cin.ignore(...) is the correct way to do what you are asking. If it isn't working right for you it is because you are not reading input correctly.Keeping your input synchronized is part of your job (as the programmer) when handling it. Unfortunately, the ubiquity of using cin >> foo typically throws a wrench in the proper understanding of user input.Get all user input with getline( cin, s ) and parse it after that. This makes sure things are properly synchronized.Also, cin.sync() is useless. Don't bother with it -- it won't help you.Hope this helps. |
cin.ignore()
to pause, then you have to add the parameters, making the "pause" command:
|
|
cin.get();
or getchar();
, then using the various forms of cin.ignore();
to try to wipe the input buffer before the next cin.getline(cin, input);
. I see now that just using one of the above listed commands does it in one step.cin >> whatever
unless i'm doing some quick and dirty debugging or something. I always use getline(cin, input)
for the reasons you just described.cin.sync()
is useless, because it did do what I was "looking for", but I now see why using this command is more clean and maintains better control of the input.