std::getline
istream& getline ( istream& is, string& str, char delim ); istream& getline ( istream& is, string& str );
Extracts characters from is and stores them into str until a delimitation character is found.
The delimiter character is delim for the first function version, and '\n' (newline character) for the second. The extraction also stops if the end of file is reached in is or if some other 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.
Notice that unlike the c-string versions of istream::getline, these string versions are implemented as global functions instead of members of the stream class.
Parameters
- is
- istream object on which the extraction operation is performed.
- str
- string object where the extracted content is stored.
- delim
- The delimiting character. The operation of extracting successive characters is stopped when this character is read.
Return Value
The same as parameter is.
Errors are signaled by modifying the internal state flags:
flag | error |
---|---|
eofbit | The end of the source of characters is reached during its operations. |
failbit | No characters were extracted because the end was prematurely found.Notice that some eofbit cases will also set failbit. |
badbit | An error other than the above happened. |
Additionally, in any of these cases, if the appropriate flag has been set with is's member function ios::exceptions, an exception of type ios_base::failure is thrown.
Example
|
|
原文链接: https://www.cnblogs.com/lexus/archive/2012/10/25/2738645.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/66951
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!