cin.get()和cin.getLine()解析
#include "iostream"
using namespace std;
void main()
{
char str1[10];
char str2[10];
char str3[10];
char str4[10];
(cin>>str1).get();//cin 以制表符,空格,换行符作为终止符 并且不抛弃不放弃终止符
cin.get(str2,10);//cin.get() 以换行符作为终止符 并且不抛弃不放弃终止符
cin.get();
cin.getline(str3,10);//cin.getline() 换行符作为终止符 但是抛弃终止符
cin.get(str4,10,'1');//不在以 '\n'作为结束 而是以 '1'
cout<<endl<<str1<<endl;
cout<<str2<<endl;
cout<<str3<<endl;
cout<<str4<<endl;
}
浙公网安备 33010602011771号