This is in C + +
The prototype of Getline () is istream& getline (IStream &is, String &str, char delim);
Where IStream &is represents an input stream, for example cin;string&str means that the string read from the input stream is stored in the string (can be arbitrarily named, str or whatever); Char Delim indicates that the character is encountered to stop reading, If not set, the system defaults to the character ' \ n ', which is the carriage return newline character (encountered carriage return stop read in).
So what happens if Getline () is used as a while judgment statement? Let's analyze the while (Getline (cin,line)) statement Note that the default carriage return stops reading here, press CTRL + Z or type EOF enter to exit the loop. In this statement, first getline reads the characters from the standard input device and then returns to the input stream CIN, noting that it is CIN, so the true judgment object of the While judgment statement is CIN, which is to determine whether there is currently a valid input stream. In this case, I think as long as your computer is not poisoned not insane how can your input stream not be effective? So in this case no matter how you enter the loop, because your input stream is valid, cannot jump out of the loop. However, some students mistakenly think that while the judgment of the sentence is line (that is, line is empty), and then want to go through the direct carriage (that is, enter an empty line) out of the loop, but found how also can not jump out of the loop. This is because your return will only terminate the read-in operation of the Getline () function. The Getline () function terminates with a while () judgment (that is, if the input stream is valid, your input stream is of course valid and satisfies the condition), so the Getline () function is run
Getline () function