cin、cin.get()、cin.getline()、getline()、gets()、getchar()
功能一:接收单个数字、字符
#include <iostream> using namespace std; int main() { int a, b; char c, d; cin >> a >> b >> c >> d; return 0; }功能二:接受一个字符数组,遇“空格”、“Tab”、“回车”结束,后面的字符不在读取。
头文件:stdio.h(c),cstdio(C++) gets从标准输入设备读字符串函数,其可以无限读取,不会判断上限,以回车结束读取 (参考:https://baike.baidu.com/item/gets/787649?fr=aladdin)
#include <iostream> #include <cstdio> using namespace std; int main(){ char str[100]; gets(str); cout<<str<<endl; return 0; }//gets_s函数用法基本一样,此处略getchar()//接受任何一个字符,包括空格、回车、tab键。
#include<iostream> using namespace std; void main() { char ch; ch = getchar(); //不能写成getchar(ch); cout << ch << endl; }