fast_io
fast_io copied to clipboard
How to scan password?
If I use scan to receive a password, it'll echo on console.
void EnableStdinEcho(bool enable) noexcept {
#ifdef WIN32
HANDLE std_in = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(std_in, &mode);
if (enable) {
mode |= ENABLE_ECHO_INPUT;
} else {
mode &= ~ENABLE_ECHO_INPUT;
}
SetConsoleMode(std_in, mode);
#else
struct termios tty;
tcgetattr(STDIN_FILENO, &tty);
if (enable) {
tty.c_lflag |= ECHO;
} else {
tty.c_lflag &= ~ECHO;
}
(void)tcsetattr(STDIN_FILENO, TCSANOW, &tty);
#endif
}
#ifdef _WIN32 #include <windows.h> #else #include <termios.h> #include <unistd.h> #endif
看样这个功能可以考虑加到fast_io中
大神英明啊,有个专门输入密码的包装更方便使用。