typedef basic_istream<char> istream;
extern istream cin;
//cin是basic_istream<char>对象
int a;
cin >> a;
//跳过开头的空白字符和回车符, 从(第一个非空白/非回车字符)开始读取, 然后直到遇到(空白字符,回车符)结束(但是并不删去)
//cin only reads up to but not including the first whitespace character, which includes
//the newline (or '\n') when you press enter.
//读取的数据与该变量类型不匹配,则会将cin的状态置为fail,导致之后所有的cin语句无法(不再)执行.
string a;getline(cin,a);//读取直到遇到\n(\n不会读取),\n会从缓冲区中清除
cout << endl;//Inserts a new-line character and flushes the stream.
char c = cin.get();//只读取一个字符, 缓冲区中的换行符,空白符也会读取
C++输入输出
于 2023-05-12 17:07:30 首次发布