istream成员总结

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 标签:

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

《istream成员总结》有186个想法

  1. This is such a great resource that you are providing and you give it away for free. I enjoy seeing websites that understand the value of providing a prime resource for free. I truly loved reading your post. Thanks!

        1. @Vinceen, 是啊,虽然勉强看得懂,但很容易漏掉某些东西,毕竟不是自己的母语。正因为这样,印度的软件业就比我们的好。

        2. @vanxining, 不过总有很多英语牛人,但那些牛人又有多少搞IT的呢,看汉文最舒服。
          不过很多知识既然是从外面来的,没有人搞翻译的话,就只能去复习英语了。

        3. @C瓜哥, 汗。瓜哥,你没看完全文 [s:32]

          我最后写了“PS:以上内容全部来至www.CPlusPlus.com。

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

          我感觉这些东西,如果被翻译了,肯定会造成理解上的困难,搞编程,学英语是必不可少的。

          再次把瓜哥砸一下,居然说哥抄袭。。。 [s:32]

        4. @Tanky Woo,
          编程讲的是思想,而不受种某种自然语言限制(如果可以,你也可以把它翻译成蒙语)
          你把别人的思想讲解一下的能力都没有吗?呵呵 [s:6]

        5. @C瓜哥, 汗了。瓜哥你就别绕了。
          其实都知道看编程类书籍不但要看国外的,而且最好看原版,不翻译的。

          再说了我这只是为了自己学习。。。我能看懂就行了。。。。干嘛要翻译。。。。
          再次砸瓜![s:32] [s:8]

发表评论

电子邮件地址不会被公开。 必填项已用*标注