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
Read More:
- CIN in C + + cin.get ()、 cin.getline (), getline(), gets() function
- The usage and difference of atoi() and stoi() functions in C + +
- C++ cin.ignore Use of ()
- Differences between length() size() and C strlen() of C + + string member functions
- use cin.get () instead of system (“pause”) to avoid the flash of C + + programs
- C#: Analysis of the difference between write() and writeline()
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- C + + pauses the black window system (“pause”); (get ch(), getchar(), system (pause)’s connection and difference
- The usage of several integer functions in MATLAB (fix, floor, ceil, round)
- Difference between isempty method and isblank method in stringutils
- The difference between sleep() and wait() in Java
- Error C2664 in C + + compilation: cannot convert parameter 2 from “const char [5]” to “lpctstr” solution.
- Solution to the problem of no C / C + + option in the new project of eclipse
- Solve the problem of error: cannot pass objects of non trivially copyable type ‘STD:: String’ in C / C + +
- The difference of four kinds of integer function (fix floor ceil round) in MATLAB
- Python how does a. Py file call classes and functions in another. Py file
- ERF and erfc functions
- C++:error C2228: left of ‘.str’ must have class/struct/union
- error C2057: expected constant expression (Can the size of an array in C language be defined when the program is running?)
- Solutions to error c2143: syntax error: missing ‘;’ before ‘type’ in C + + program compilation