Am I the only one noticed?

Pages: 12
Am I the only one noticed that if you use cin.get() you can pause but you may still type characters after that? So ... what should I use instead?
Console functions provided by third party libraries. Basically, anything but streams.
What? cin.get() waits for you to press the required character, default is newline.
You can still use cin.get() - the characters aren't read, they're ignored. They're printed by the console regardless.
They're printed by the console regardless.
That's what OP doesn't want.
OH. I saw Duoas talking about something like "SetConsoleMode()" for windows. I guess he could try that, or use ncurses, if it can do that (which it probably can).

Then again this boost thing seems to be able to do virtually everything, so maybe you can try that.
...Which is why I don't recommend using cin.get().
See http://www.cplusplus.com/forum/articles/7312/
I really think you should have mentioned manually starting a console, in that article.
Unfortunately, I cannot change that now. However, an upcoming article will address setting up the Windows console as a programming environment.
Hmm ... I made this little code (through Duoas's link) and it terminates successfully after a key is pressed :)

By the way why is you name Duoas?

1
2
3
4
5
6
int wait(){
  int c;
  printf( "\nPress a key to continue..." );
  c = getch();
  if (c == 0 || c == 224) getch();     
}
Don't use getch(), it's severely deprecated. Use getchar(); instead. You can std::cout << "\b \b" as soon as the key is pressed if you don't want the echo...
getchar() is C for std::cin.get().
Last edited on
Then use cin.get()...
Congratulations. You just reset the conversation to its starting point.
Oh yeah :l

That's entrapment >:(
Last edited on
So ..... I replace getch() with getchar() ? Or are we forever trapped?
You can use getch() as long as it's not from conio. The one provided by any of the curses libraries will work.
I am sorry but what is the curses library? should I use getchar instead?
Use the OS-specific versions at the bottom if you are doing anything professional. (Well, if you are doing anything professional, don't PAUSE at all...)

For stupid stuff, or code that will only run on one platform, use the other things. Curses is overkill for a PAUSE function. <conio.h> is fine for that. Just remember, it won't work elsewhere. (Like on your professor's computer.)

"Duoas" is the short version (that is, one that most people can read and pronounce fairly well) of "Dùthomhas" -- which is Irish for "Enigma". ;-]
http://pdcurses.sourceforge.net/
http://www.gnu.org/software/ncurses/

PDcurses is the second result on Google, by the way.

should I use getchar instead?
If you are, you might as well use std::cin.get(). It's the same thing.
Last edited on
Is it unix users only? Or is windows included
Pages: 12