📄 istream.htm
字号:
<html>
<head>
<title> The basic_istream(istream) Class</title>
</head>
<body bgcolor="#FFFFFF">
<img src="istrban.gif">
<pre>
<font size=5>Class Name</font> basic_istream
<font size=5>Header File</font> <istream>
<font size=5>Classification</font> Input/Output (Format Class)
</pre>
<a href="istream.htm#diagram">Class Relationship Diagram</a><br>
<br>
<a href="istream.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>
<a href="ios.htm">basic_ios</a>
<h1>Methods</h1>
<pre>
<a href="istream.htm#istream1">explicit basic_istream(basic_streambuf<charT,traits>* Sb)</a><br>
<a href="istream.htm#istream2">virtual ~basic_istream()</a><br>
<a href="istream.htm#gcount">streamsize gcount() const</a><br>
<a href="istream.htm#get1">int_type get()</a><br>
<a href="istream.htm#get2">basic_istream<charT,traits>& get(char_type& CharValue)</a><br>
<a href="istream.htm#get3">basic_istream<charT,traits>& get(char_type* Str, streamsize Num)</a><br>
<a href="istream.htm#get4">basic_istream<charT,traits>& get(char_type* Str, streamsize Num, char_type delim)</a><br>
<a href="istream.htm#get5">basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& Sb)</a><br>
<a href="istream.htm#get6">basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& Sb, char_type Delim)</a><br>
<a href="istream.htm#getline1">basic_istream<charT,traits>& getline(char_type* Str, streamsize Num)</a><br>
<a href="istream.htm#getline2">basic_istream<charT,traits>& getline(char_type* Str, streamsize Num, char_type Delim)</a><br>
<a href="istream.htm#ignore">basic_istream<charT,traits>& ignore (streamsize N = 1, int_type Delim = traits::eof())</a><br>
<a href="istream.htm#peek">int_type peek()</a><br>
<a href="istream.htm#read">basic_istream<charT,traits>& read (char_type* Str, streamsize Num)</a><br>
<a href="istream.htm#readsome">streamsize readsome(char_type* Str, streamsize Num)</a><br>
<a href="istream.htm#putback">basic_istream<charT,traits>& putback(char_type CharValue)</a><br>
<a href="istream.htm#unget">basic_istream<charT,traits>& unget()</a><br>
<a href="istream.htm#sync">int sync()</a><br>
<a href="istream.htm#tellg">pos_type tellg()</a><br>
<a href="istream.htm#seekg1">basic_istream<charT,traits>& seekg(pos_type X)</a><br>
<a href="istream.htm#seekg2">basic_istream<charT,traits>& seekg(off_type X, ios_base::seekdir Dir)</a><br>
</pre>
<a href="istream.htm#example"><h2>Example</h2></a><br>
<hr>
<a name="desc"><h3>Class Description</h3></a>
<p>
The basic_istream class models an input stream in C++. When data is taken from a stream
of type basic_ostream and stored in a variable, it is called an extraction. The data is
extracted from a stream in order to be input to a variable. The >> is called the extraction
operator. The right shift operator is overloaded to perform input operations on built in
and user defined data types. The basic_istream has member functions that accept into
the stream generic sequences of data and converts them to built in types, user defined
types, or user defined structures. This class represents a node class and can therefore be
used as a base class for user defined classes. The basic_istream class has a typedef
and is often referred to as istream.
</p>
<hr>
<pre>
<a name="istream1">Method basic_istream()</a>
Access Public
Classification Constructor
Syntax explicit basic_istream(basic_streambuf<charT,traits>* Sb)
Parameters Sb is the buffer object that will be used for the istream
object.
Return None
</pre>
<h3>Description</h3>
<p>
This basic_istream() method is used to construct an object of type basic_istream.
</p>
<hr>
<pre>
<a name="istream2">Method basic_istream()</a>
Access Public
Classification Destructor
Syntax ~basic_istream()
Parameters None
Return None
</pre>
<h3>Description</h3>
<p>
This basic_istream() method is destructs an object of type basic_istream.
</p>
<hr>
<pre>
<a name="gcount">Method gcount()</a>
Access Public
Classification Accessor
Syntax streamsize gcount() const
Parameters None
Return This method returns the number of characters read
by the last unformatted input operation.
</pre>
<h3>Description</h3>
<p>
This gcount() method returns the number of characters successfully extracted during the last
call to one of the unformatted input operations such as:
<pre>
get()
getline()
read()
readsome()
</pre>
</p>
<hr>
<pre>
<a name="get1">Method get()</a>
Access Public
Classification Modifier
Syntax int_type get()
Parameters None
Return This method returns the character extracted. If there
is no character to extract and no error has occurred
this method returns eof().
</pre>
<h3>Description</h3>
<p>
This get() method extracts a single character from the input stream. An error
during this operation could result in an thrown exception. E.g.
<pre>
ios_base::failure
</pre>
</p>
<hr>
<pre>
<a name="get2">Method get()</a>
Access Public
Classification Modifier
Syntax basic_istream<charT,traits>& get(char_type& CharValue)
Parameters The value extracted from the stream will be assigned to
CharValue.
Return This method returns a reference to the current istream object.
</pre>
<h3>Description</h3>
<p>
This get() method extracts a single character from the input stream. Since the iostreams are
template classes, the type character extracted from the input stream will be charT, based on
whatever the instantiation for the basic_istream is. A reference to the basic_istream object
will be returned. It will perform no translation or conversion on the character. The character
will be taken from a stream of type basic_istream and stored into CharValue. If this method
cannot extract a character failbit will be set.
An error during this operation could result in an thrown exception. E.g.
<pre>
ios_base::failure
</pre>
</p>
<hr>
<pre>
<a name="get3">Method get()</a>
Access Public
Classification Modifier
Syntax basic_istream<charT,traits>& get(char_type* Str, streamsize Num)
Parameters Num -1 is the number of character extracted and stored in memory beginning
at the location pointed to Str.
Return This method returns a reference to the current istream object.
</pre>
<h3>Description</h3>
<p>
This get() method extracts Num characters and stores them at the location pointed to by
Str, It will perform no translation or conversion on the characters.
An error during this operation could result in an thrown exception. E.g.
<pre>
ios_base::failure
</pre>
</p>
<hr>
<pre>
<a name="get4">Method get()</a>
Access Public
Classification Modifier
Syntax basic_istream<charT,traits>& get(char_type* Str, streamsize Num, char_type Delim)
Parameters Num - 1 is the number of character extracted and stored in memory beginning
at the location pointed to Str. Delim is a delimiter that signals a stopping
place for the get() method.
Return This method returns a reference to the current istream object.
</pre>
<h3>Description</h3>
<p>
This get() method will extract characters from the attached buffer until either Num number of
characters has been extracted, the Delim is reached, or some error condition is caused,
whichever happens first. The error condition could be the get() member function trying
to extract beyond the EOF. The streamsize Num is the most characters that will be extracted
from the input stream. Delim is a character that will cause the extraction process to terminate. Obviously if the extraction process does not encounter the Delim then it will attempt to extract n characters. An error condition occurs if the source of the extraction does not contain n characters. This form of the get() member function will leave the delimiter Delim in the stream. It will not extract Delim and store it in destination.
An error during this operation could result in an thrown exception. E.g.
<pre>
ios_base::failure
</pre>
</p>
<hr>
<pre>
<a name="get5">Method get()</a>
Access Public
Classification Modifier
Syntax basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& Sb)
Parameters Sb is a streambuf object that will receive characters extracted from the
input stream.
Return This method returns a reference to the current istream object.
</pre>
<h3>Description</h3>
<p>
This get() method will extract characters from the attached buffer until either '\n' or
its equivalent is reached. An error during this operation could result in an thrown
exception. E.g.
<pre>
ios_base::failure
</pre>
</p>
<hr>
<pre>
<a name="get6">Method get()</a>
Access Public
Classification Modifier
Syntax basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& Sb, char_type Delim)
Parameters Sb is a streambuf object that will receive characters extracted from the
input stream. Delim is a character that will cause the extraction
to terminate.
Return This method returns a reference to the current istream object.
</pre>
<h3>Description</h3>
<p>
This get() method will extract characters from the attached buffer until
<pre>
eof() condition occurs
Delim is reached
An exception occurs (In this case it is not propagated)
</pre>
Delim is not stored in the Streambuf object. If no characters are extrated during this operation
a exception can be thrown. E.g. If eof() is reached the eofbit is set.
<pre>
ios_base::failure
</pre>
</p>
<hr>
<pre>
<a name="getline1">Method getline()</a>
Access Public
Classification Modifier
Syntax basic_istream<charT,traits>& getline(char_type* Str, streamsize Num)
Parameters Num - 1 is the number of character extracted and stored in memory beginning
at the location pointed to Str.
Return This method returns a reference to the current istream object.
</pre>
<h3>Description</h3>
<p>
This getline() method extracts Num characters and stores them at the location pointed to by
Str, It will perform no translation or conversion on the characters.
Delim is extracted from the stream. If no characters are extrated during this operation
a exception can be thrown. E.g. If eof() is reached the eofbit is set.
<pre>
ios_base::failure
</pre>
</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -