getchar()键入一个回车——返回值为’\n’,ASCII码为10——换行符
getchar()流输入函数,自动把’\r’‘转换为’\n’
char ch = getchar(); //输入回车
cout << int(ch); //输出10(='\n')
#include<conio.h>
getch()键入一个回车——返回值为’\r’,ASCII码为13——回车符
getch()和getche()或_getch()或_getche()
#include<conio.h>
char ch = _getch(); //输入回车
cout << int(ch); //输出13(='\r')
- 2笔记
★ 从键盘输入含空格字符串的方法(不同编译器不同)
● VS2019 :有gets_s,无gets, 有fgets
● Dev C++ :有gets, 无gets_s,有fgets
● fgets函数的原型定义为:
fgets(字符数组名,最大长度,stdin);
但与gets/gets_s的表现有不同,请自行观察