-
cin.get();
Is this command: cin.get(); compiler specific?? because I have been hunting high and low for a way to make my screen oause without using system("pause"). I have tryed all the following:
cin.get();
cin.sync();
get.char();
getch();
the only one that works is getch(), but I get warnings about using it, I am using Microsoft Visual 2005 beta compiler now, and on my old DevC++ compiler which I still have as backup, all the above work apart from cin.get. What should I do?
I have looked at the FAQ and googled it, I know I can use getch() for now, but there must be another command I can use apart from system("pause"), which is frowned apon
-
std::cin.get() is part of the C++ standard library.
As for your answer, it can be found by searching, and might result in you finding a thread like this one.
-
get() is a member function of basic_istream, so cin.get() is legal. Similarly for cin.sync(). get() returns the next byte in the stream. cin.get() won't do what you want though, as it treats the standard input like a file. In other words, if the user types ABC<enter> it will return 'A' [or, more accurately, the integer value associated with 'A'] after the <enter> is hit. If cin.get() is called again, with no other operations that get input from cin, the next call will return 'B' .
get.char() is meaningless, as char is a keyword.
getch() will do what you want, but is compiler dependent. Unfortunately, there is no equivalent function supported in either the C or C++ standards. The reason for this is that such functions assume a computer with a keyboard to get keystrokes from, and both C and C++ are designed to work on machines that don't necessarily have a keyboard.
system("pause"); is not specifically frowned upon because it is compiler dependent. It only works with Microsoft operating systems under certain conditions (eg if the user installs a different command interpreter it won't necessarily work). In other words, depending on how the system is set up, it won't work ..... which is not exactly a good idea if you are providing software to people and can't control how they set up their operating system.