|
istream::getlinepublic member function
istream& getline (char* s, streamsize n ); istream& getline (char* s, streamsize n, char delim ); Get line from stream Extracts characters from the input sequence and stores them as a c-string into the array beginning at s.Characters are extracted until either (n - 1) characters have been extracted or the delimiting character is found (which is delim if this parameter is specified, or '\n' otherwise). The extraction also stops if the end of file is reached in the input sequence or if an error occurs during the input operation. If the delimiter is found, it is extracted and discarded, i.e. it is not stored and the next input operation will begin after it. If you don't want this character to be extracted, you can use member get instead. The ending null character that signals the end of a c-string is automatically appended to s after the data extracted. The number of characters read by this function can be obtained by calling to the member function gcount. A global function with the same name exists in header <string>. This global function provides a similar behavior, but with standard C++ string objects instead of c-strings: see getline (string). Parameters
Return ValueThe function returns *this.Errors are signaled by modifying the internal state flags:
Additionally, in any of these cases, if the appropriate flag has been set with member function ios::exceptions, an exception of type ios_base::failure is thrown. Example
This example ilustrates how to get lines from the standard input stream ( cin ). Basic template member declarations( basic_istream<charT,traits> )
See also
|