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

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    <a href="setf.html">setf</a><br>    <a href="unsetf.html">unsetf</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    flush  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  ostream&amp; flush();</pre>  <p>The flush() function causes the buffer for the current output  stream to be actually written out to the attached device.</p>  <p>This function is useful for printing out debugging information,  because sometimes programs abort before they have a chance to write  their output buffers to the screen. Judicious use of flush() can  ensure that all of your debugging statements actually get  printed.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="put.html">put</a><br>    <a href="write.html">write</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    gcount  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  streamsize gcount();</pre>  <p>The function gcount() is used with input streams, and returns the  number of characters read by the last input operation.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="get.html">get</a><br>    <a href="getline.html">getline</a><br>    <a href="read.html">read</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    get  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  int get();  istream&amp; get( char&amp; ch );  istream&amp; get( char* buffer, streamsize num );  istream&amp; get( char* buffer, streamsize num, char delim );  istream&amp; get( streambuf&amp; buffer );  istream&amp; get( streambuf&amp; buffer, char delim );</pre>  <p>The get() function is used with input streams, and either:</p>  <ul>    <li>reads a character and returns that value,</li>    <li>reads a character and stores it as <em>ch</em>,</li>    <li>reads characters into <em>buffer</em> until <em>num</em> - 1    characters have been read, or <strong>EOF</strong> or newline    encountered,</li>    <li>reads characters into <em>buffer</em> until <em>num</em> - 1    characters have been read, or <strong>EOF</strong> or the    <em>delim</em> character encountered (<em>delim</em> is not read    until next time),</li>    <li>reads characters into buffer until a newline or    <strong>EOF</strong> is encountered,</li>    <li>or reads characters into buffer until a newline,    <strong>EOF</strong>, or <em>delim</em> character is encountered    (again, <em>delim</em> isn&#39;t read until the next get() ).</li>  </ul>  <p>For example, the following code displays the contents of a file  called temp.txt, character by character:</p>  <pre class="example-code">   char ch;   ifstream fin( &quot;temp.txt&quot; );   while( fin.get(ch) )     cout &lt;&lt; ch;   fin.close();         </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="gcount.html">gcount</a><br>    <a href="getline.html">getline</a><br>    (C++ Strings) <a href="../cppstring/getline.html">getline</a><br>    <a href="ignore.html">ignore</a><br>    <a href="peek.html">peek</a><br>    <a href="put.html">put</a><br>    <a href="read.html">read</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    getline  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  istream&amp; getline( char* buffer, streamsize num );  istream&amp; getline( char* buffer, streamsize num, char delim );</pre>  <p>The getline() function is used with input streams, and reads  characters into <em>buffer</em> until either:</p>  <ul>    <li><em>num</em> - 1 characters have been read,</li>    <li>a newline is encountered,</li>    <li>an <strong>EOF</strong> is encountered,</li>    <li>or, optionally, until the character <em>delim</em> is read. The    <em>delim</em> character is not put into buffer.</li>  </ul>  <p>For example, the following code uses the getline function to  display the first 100 characters from each line of a text file:</p>  <pre class="example-code">  ifstream fin("tmp.dat");  int MAX_LENGTH = 100;  char line[MAX_LENGTH];  while( fin.getline(line, MAX_LENGTH) ) {    cout << "read line: " << line << endl;  }</pre>  <p>If you'd like to read lines from a file into <a  href="../cppstring/index.html">strings</a> instead of character arrays,  consider using the <a href="../cppstring/getline.html">string  getline</a> function.</p>  <p>Those using a Microsoft compiler may find that getline() reads an  extra character, and should consult the documentation on the <a href=  "http://support.microsoft.com/default.aspx?scid=kb;EN-US;q240015">Microsoft  getline bug</a>.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="gcount.html">gcount</a><br>    <a href="get.html">get</a><br>    (C++ Strings) <a href="../cppstring/getline.html">getline</a><br>    <a href="ignore.html">ignore</a><br>    <a href="read.html">read</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    good  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  bool good();</pre>  <p>The function good() returns true if no errors have occurred with  the current stream, false otherwise.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="bad.html">bad</a><br>    <a href="clear.html">clear</a><br>    <a href="eof.html">eof</a><br>    <a href="fail.html">fail</a><br>    <a href="rdstate.html">rdstate</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    ignore  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  istream&amp; ignore( streamsize num=1, int delim=<strong>EOF</strong> );</pre>  <p>The ignore() function is used with input streams. It reads and  throws away characters until <em>num</em> characters have been read  (where <em>num</em> defaults to 1) or until the character  <em>delim</em> is read (where <em>delim</em> defaults to  <strong>EOF</strong>).</p>  <p>The ignore() function can sometimes be useful when using the  getline() function together with the &gt;&gt; operator.  For  example, if you read some input that is followed by a newline using  the &gt;&gt; operator, the newline will remain in the input as the  next thing to be read.  Since getline() will by default stop reading  input when it reaches a newline, a subsequent call to getline() will  return an empty string.  In this case, the ignore() function could  be called before getline() to "throw away" the newline.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="get.html">get</a><br>    <a href="getline.html">getline</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    open  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  void open( const char *filename );  void open( const char *filename, openmode mode = default_mode );</pre>  <p>The function open() is used with file streams. It opens  <em>filename</em> and associates it with the current stream. The  optional <a href="../io_flags.html#mode_flags">io stream mode  flag</a> <em>mode</em> defaults to ios::in for ifstream, ios::out for  ofstream, and ios::in|ios::out for fstream.</p>  <p>If open() fails, the resulting stream will evaluate to false when  used in a Boolean expression. For example:</p>  <pre class="example-code"> ifstream inputStream; inputStream.open(&quot;file.txt&quot;); if( !inputStream ) {   cerr &lt;&lt; &quot;Error opening input stream&quot; &lt;&lt; endl;   return; }              </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="constructors.html">I/O Constructors</a><br>    <a href="close.html">close</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    peek  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  int peek();</pre>  <p>The function peek() is used with input streams, and returns the  next character in the stream or <strong>EOF</strong> if the end of  file is read. peek() does not remove the character from the  stream.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="get.html">get</a><br>    <a href="putback.html">putback</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    precision  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  streamsize precision();  streamsize precision( streamsize p );</pre>  <p>The precision() function either sets or returns the current number  of digits that is displayed for floating-point variables.</p>  <p>For example, the following code sets the precision of the cout  stream to 5:</p>  <pre class="example-code">   float num = 314.15926535;   cout.precision( 5 );   cout &lt;&lt; num;           </pre>  <p>This code displays the following output:</p>  <pre class="example-code">   314.16               </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="fill.html">fill</a><br>    <a href="width.html">width</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    put  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  #include &lt;fstream&gt;  ostream&amp; put( char ch );</pre>  <p>The function put() is used with output streams, and writes the  character <em>ch</em> to the stream.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="flush.html">flush</a><br>    <a href="get.html">get</a><br>    <a href="write.html">write</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>

⌨️ 快捷键说明

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