下面代码实现的是输入一个小写字母只能看到大写字母
#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”) 之间的代码的执行都不会回显
本文介绍了一个简单的C++程序,该程序通过标准输入接收一个小写字母,并将其转换为大写字母输出。使用了termios库来控制终端输入属性,并通过system调用禁用和启用字符回显。
538

被折叠的 条评论
为什么被折叠?



