linux下c++如何输入不回显
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <iostream>
using namespace std;
int main(void){
char c;
static struct termios oldt, newt;
tcgetattr( STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON);
tcsetattr( STDIN_FILENO, TCSANOW, &newt);
system("stty -echo");
while((c=getchar())!= 'e') {
char d = c + 'A' - 'a';
cout << d << endl;
}
system("stty echo");
tcsetattr( STDIN_FILENO, TCSANOW, &oldt);
return 0;
}
其中system("stty -echo") 与 system("stty echo") 之间的代码的执行都不会回显