cin.getline ():
usage: receive a string, which can receive spaces and output. It needs to include & lt; CString & gt;
char m[20];
cin.getline(m,5);
cout<<m<<endl;
Input: jkljkljkl
output: jklj
Receive 5 characters into m, and the last one is’ \ 0 ‘, so only 4 characters can be output;
Extension:
1 cin.getline () actually has three parameters, cin.getline (variables of receiving string, number of receiving characters, end characters)
2. When the third parameter is omitted, the system defaults to ‘\ 0’
3 cin.getline () to read cin.getline When jlkjkljkl is input, jklj is output; when jkaljkljkl is input, JK is output
Getline():
usage: to receive a string, which can receive spaces and output. It needs to include & lt; CString & gt;
string str;
getline(cin,str);
cout<<str<<endl;
Input: jkljkljkl
output: jkljkljkl
Input: JKL jfksldfj jklsjfl
output: JKL jfksldfj jklsjfl