#include <windows.h>
class echo_input
{
HANDLE hStdIn_;
DWORD mode_;
public:
explicit echo_input(bool b = true) {
hStdIn_ = GetStdHandle(STD_INPUT_HANDLE);
save();
if (b)
enable();
else
disable();
}
~echo_input() { restore(); }
void enable() const { SetConsoleMode(hStdIn_, mode_ | ENABLE_ECHO_INPUT); }
void disable() const { SetConsoleMode(hStdIn_, mode_ & ~ENABLE_ECHO_INPUT); }
void save() { GetConsoleMode(hStdIn_, &mode_); }
void restore() const { SetConsoleMode(hStdIn_, mode_); }
};