How does one prevent cin from printing to a console screen in C++? Given this simple program:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World..." << endl;
cin.clear();
cout << "Press ENTER to Continue..." << endl;
cin.ignore();
exit(0);
}
So if a user jams away at the keyboard, nothing will happen until ENTER is pressed. This currently works great, but cin dumps the keypresses to the console. How do I prevent this behavior?
Edit: I’m working in Visual Studio 2010, and I ask this simple question because I want something not platform specific.
On Windows, you need
SetConsoleMode.There is no standard platform independent way, although of course you can write your own
disable_echo()function and use#if _WIN32and#if __LINUX__to provide platform-specific implementations of a platform-independent interface.