getch(),getche()和getchar()使用区别

版权声明:吴鹏 https://blog.csdn.net/qq_28311415/article/details/81167211

getchar()

    函数名:getchar()
    头文件:stdio.h
 功  能:从I/O流中读字符
 原  型:int getchar(void);

getch()
  函数名:getch()
  头文件:conio.h
  功  能:从控制台读取一个字符,但不显示在屏幕上
  原  型:int getch(void)
  返回值:读取的字符

getche()
    函数名:getche()
    头文件:conio.h
 功  能:从控制台取字符(带回显)
 用  法:int getche(void);

getch()和getche()函数

 这两个函数都是从键盘上读入一个字符。其调用格式为:
  getch();
  getche();
 两者的区别是: getch()函数不将读入的字符回显在显示屏幕上, 而getche()函数却将读入的字符回显到显示屏幕上。利用回显和不回显的特点, 这两个函数经常用于交互输入的过程中完成暂停等功能。

#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
    char c = _getche();
	cout << endl;
	cout << "_getche()";
	cout << c << endl;
    c = _getch();
	cout << endl;
	cout <<"_getch():"<< c << endl;
		//setbuf(stdin, NULL);
		c = getchar();
	cout << c << endl;
}

猜你喜欢

转载自blog.csdn.net/qq_28311415/article/details/81167211
今日推荐