⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 istream.htm

📁 使用C++开发过程中
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<hr>

<pre>
<a name="getline2">Method            getline()</a>

Access            Public

Classification    Modifier

Syntax            basic_istream&lt;charT,traits&gt;& getline(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 the character that causes
                  the get operation to terminate.
 

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 continue to extract characters until
<pre>
              
                 Num - 1 characters have been extracted   
                 eof() condition occurs
                 Delim  is reached
</pre>



It will perform no translation or conversion on the characters.     
Delim is extracted from the stream and is not stored. If no characters are extracted
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="ignore">Method            ignore()</a>

Access            Public

Classification    Modifier

Syntax            basic_istream&lt;charT,traits&gt;& ignore (streamsize N = 1, int_type Delim = traits::eof())

Parameters        N is the number of characters to ignore in the input stream. Delim is a
                  character that can cause the ignore() operation to terminate.
                 
 

Return            This method returns a reference to the current istream object.            

</pre>

<h3>Description</h3>
<p>

The ignore() method extracts up to N Characters and discards them.
It will continue to extract characters until
<pre>
              
                 N characters have been extracted   
                 eof() condition occurs
                 Delim  is reached
</pre>


Delim is extracted from the stream and is not stored. If no characters are extracted
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="peek">Method            peek()</a>

Access            Public

Classification    Accessor

Syntax            int_type peek()

Parameters        None
 

Return            This method returns a copy of the next character in the input
                  stream.

</pre>

<h3>Description</h3>
<p>

The peek() returns a copy of the next character from the input stream without
extracting the character.
</p>
<hr>

<pre>
<a name="read">Method            read()</a>

Access            Public

Classification    Modifier

Syntax            basic_istream&lt;charT,traits&gt;& read (char_type* Str, streamsize Num)

Parameters        Str is a Pointer to a location where Num characters will be stored.
 
Return            This method returns a reference to the current istream object.            

</pre>

<h3>Description</h3>
<p>

The read() method will accept an array or a pointer to a charT and the number of bytes to be read.
The pointer  points to a buffer or an array  that will store the block of characters. 
It points to a buffer of charT. The read() member function has been overloaded and can be used 
to extract data from the attached stream buffer and store it into a character array.
</p>
<hr>

<pre>
<a name="readsome">Method            readsome()</a>

Access            Public

Classification    Modifier

Syntax            streamsize readsome(char_type* Str, streamsize Num)

Parameters        Str is a Pointer to a location where Num characters will be stored.
 
Return            <a href="istream.htm#gcount">gcount()</a>            

</pre>

<h3>Description</h3>
<p>

The readsome() method will accept an array or a pointer to a charT and the number of bytes to be read.
The pointer  points to a buffer or an array  that will store the block of characters. 
This method will read the min(rdbuf()-&gt;in_avail(),Num) of bytes.

</p>
<hr>

<pre>
<a name="putback">Method            putback()</a>

Access            Public

Classification    Modifier

Syntax            basic_istream&lt;charT,traits&gt;& putback(char_type CharValue)

Parameters        The character value to be stored back into the stream.
 
Return            This method returns a reference to the current istream object.

</pre>

<h3>Description</h3>
<p>
The putback() method pushes the character CharValue back onto the input stream.
</p>
<hr>


<pre>
<a name="unget">Method            unget()</a>

Access            Public

Classification    Modifier

Syntax            basic_istream&lt;charT,traits&gt;& unget()

Parameters        None
 
Return            This method returns a reference to the current istream object.

</pre>

<h3>Description</h3>
<p>
The unget() method  rewinds the current pointer to the input stream one character.
</p>
<hr>

<pre>
<a name="sync">Method            sync()</a>

Access            Public

Classification    Modifier

Syntax            int sync()

Parameters        None
 
Return            If rdbuf() returns Null this method returns -1. Otherwise it
                  returns rdbuf()-&gt;pubsync().

</pre>

<h3>Description</h3>
<p>
The sync() method  attempts to synchronize the internal arrays that are kept by its streambuf
object with the connected stream and any external buffers.

</p>
<hr>

<pre>
<a name="tellg">Method            tellg()</a>

Access            Public

Classification    Accessor

Syntax            pos_type tellg()

Parameters        None
 
Return            The tellg() method returns the current location of the get pointer.

</pre>

<h3>Description</h3>
<p>
The tellg() method returns the current location of the get pointer(the current location in the
input stream).
</p>
<hr>

<pre>
<a name="seekg1">Method            seekg()</a>

Access            Public

Classification    Modifier

Syntax            basic_istream&lt;charT,traits&gt;& seekg(pos_type X)

Parameters        None
 
Return            This method returns a reference to the current istream object.

</pre>

<h3>Description</h3>
<p>
This seekg() moves the get pointer to position X relative to the beginning of the istream. This
method action is interpreted as an absolute position from the beginning of the stream. The absolute
position that X refers to is normally obtained through a call to tellg().
</p>
<hr>

<pre>
<a name="seekg2">Method            seekg()</a>

Access            Public

Classification    Accessor

Syntax            basic_istream&lt;charT,traits&gt;& seekg(off_type X, ios_base::seekdir Dir)

Parameters        X is an offset in the input stream relative to Dir.  Dir can take on
                  the following values.

<pre>
                                   ios_base::beg
                                   ios_base::cur
                                   ios_base::end
</pre>                               
 
Return            This method returns a reference to the current istream object.

</pre>

<h3>Description</h3>
<p>
This seekg() moves the get pointer to position X relative to Dir in the input stream.
</p>
<hr>







<p>
<a name="diagram"><h2>The Class Relationship Diagram of basic_istream</h2></a>
<img src="istream.gif">
</p>
<hr>
<a name="example"></a>
<img src="lego.gif">
<pre>


    6   #include &lt;iostream&gt;
    7   #include &lt;sstream&gt;
    8   #include &lt;string&gt;
    9   
   10   using namespace std;
   11   
   12   void main(void)
   13   {
   14      string Source("These are the voyages....");
   15      char Dest[81] = "";
   16      stringbuf Buffer(Source);
   17      istream InputStream(&Buffer);
   18      if(!InputStream){
   19          cerr &lt;&lt; "Error Setting up stream";
   20      }
   21      InputStream.get(Dest,81,'e');
   22      cout &lt;&lt; Dest &lt;&lt; endl;
   23      InputStream.seekg(0,ios_base::beg);
   24      InputStream.get(Dest,InputStream.rdbuf()-&gt;in_avail(),'\n');
   25      cout &lt;&lt; Dest &lt;&lt; endl;
   26      InputStream.seekg(0,ios_base::beg);
   27      InputStream.get(Dest,5,'\n');
   28      cout &lt;&lt; Dest &lt;&lt; endl;
   29   }
</pre>
<hr>
</body>
</html>





⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -