码迷,mamicode.com
首页 > 编程语言 > 详细

linux下c++如何输入不回显

时间:2019-09-04 21:37:12      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:clu   stat   anon   执行   main   ESS   getch   class   term   

#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”) 之间的代码的执行都不会回显

 

linux下c++如何输入不回显

标签:clu   stat   anon   执行   main   ESS   getch   class   term   

原文地址:https://www.cnblogs.com/qiumingcheng/p/11461341.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!