About novice C ++ cin return value

cin is the standard input stream of C ++ , which is itself an object that there is not a return value.

However, there is often similar to the while ( cin call >> a), there is not cin return value, should focus on ">>" input operator, in fact, what is it in the end return
">>" operator overloads istream & operator >> (istream &, T &); return value, wherein the second parameter is determined by the type of subsequent parameters cin >>.
Return value type istream & type, whose return value is in most cases itself cin (non-zero value), input only when an EOF, the return value is 0.
Therefore, this method will have the following successive read cin
1 cin>>x>>y
When all of the input data, input by means of the EOF, can exit this loop while (cin >> a).
EOF input method, the input ctrl + z Windows, input ctrl + d under Linux.
 
In like an ssize_t  getline (char ** lineptr, n-size_t *, the FILE * Stream);
// getline (), the display Return value as input, iuput stream data is acquired, is the first parameter in C ++ getline manual 
// similar following code, from CIN (standard input stream
acquire content), the return value for access to content, when faced with EOF, return 0.
1 if(!getline(cin, line))
2 {
3   break;        
4 }

 


  

Guess you like

Origin www.cnblogs.com/CooCoChoco/p/11932985.html