Tanky WooRSS

istream成员总结

07 Dec 2010
这篇博客是从旧博客 WordPress 迁移过来,内容可能存在转换异常。

1.get

istream& get ( char& c ); istream& get ( char* s, streamsize n ); istream& get ( char* s, streamsize n, char delim ); istream& get ( streambuf& sb); istream& get ( streambuf& sb, char delim );

Get unformatted data from stream

These member functions perform unformatted input operations. Depending on the type and number of arguments the function behaves in the following way:

istream& get ( char& c ); Extracts a character from the stream and stores it in c. istream& get (char* s, streamsize n ); Extracts characters from the stream 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 '\n' is found. 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 delimiting character is found, it is not extracted from the input sequence and remains as the next character to be extracted. Use getline if you want this character to be extracted (and discarded). The ending null character that signals the end of a c-string is automatically appended at the end of the content stored in s.istream& get (char* s, streamsize n, char delim ); Same as above, except that the delimiting character is the one specified indelim instead of '\n'. istream& get (streambuf& sb); Extracts characters from the stream and inserts them in the stream buffer sb until either the delimiting character '\n' is found or end of file is reached. The extraction also stops if an error occurs either in the input sequence controled by the stream or in the output sequence controlled by sb. istream& get (streambuf& sb, char delim ); Same as above, except that the delimiting character is the one specified indelim instead of '\n'.The number of characters read by any of the previous input operations can be obtained by calling to the member function gcount.

_Parameters _c A char variable to store the extracted character. s A pointer to an array of characters where the string is stored as a c-string n Maximum number of characters to store (including the ternimating null character). This is an integer value of type streamsize. delim The delimiting character. The operation of extracting succesive characters is stopped when this character is read. This parameter is optional, if not specified the function considers '\n' (a newline character) to be the delimiting character. sb An output stream buffer (an object of class streambuf or any of its derived classes).


2.getline

istream& getline (char* s, streamsize n ); istream& getline (char* s, streamsize n, char delim );

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.

Parameters s A pointer to an array of characters where the string is stored as a c-string. n Maximum number of characters to store (including the terminating null character). This is an integer value of type streamsize. If the function stops reading because this size is reached, the failbit internal flag is set. delim The delimiting character. The operation of extracting succesive characters is stopped when this character is read. This parameter is optional, if not specified the function considers '\n' (a newline character) to be the delimiting character.


3.ignore

istream&  ignore ( streamsize n = 1, int delim = EOF );

Extract and discard characters

Extracts characters from the input sequence and discards them.The extraction ends when n characters have been extracted and discarded or when the character delim is found, whichever comes first. In the latter case, the delim character itself is also extracted.

Parameters n Maximum number of characters to extract (and ignore). This is an integer value of type streamsize. delim Delimiting character.


4.peekint peek ( );

Peek next character

Reads and returns the next character without extracting it, i.e. leaving it as the next character to be extracted from the stream.


5.gcount

streamsize  gcount ( ) const;

Get number of characters extracted by last unformatted input operation

Returns the number of characters extracted by the last unformatted input operation performed on the object.The unformatted input operations that modify the value returned by this function are those performed by the following member functions: get, getline, ignore, peek, read, readsome, putback and unget.Notice though, that peek, putback and unget do not extract characters. So gcount will always return zero after a call to any of these.

PS:以上内容全部来至www.CPlusPlus.com

了解更多可以查看:http://www.cplusplus.com/reference/iostream/istream/  

Tanky Woo 标签: C/C++get()getline()peek()ignore()gcount()