📄 constructors.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head> <meta name="generator" content= "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org"> <title>I/O Constructors</title> <link href="../cppreference.css" rel="stylesheet" type="text/css"></head><body><table> <tr> <td> <div class="body-content"> <div class="header-box"> <a href="../index.html">cppreference.com</a> > <a href= "index.html">C++ I/O</a> > <a href="constructors.html">I/O Constructors</a> </div> <div class="name-format"> I/O Constructors </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> #include <fstream> fstream( const char *filename, openmode mode ); ifstream( const char *filename, openmode mode ); ofstream( const char *filename, openmode mode );</pre> <p>The fstream, ifstream, and ofstream objects are used to do file I/O. The optional <em>mode</em> defines how the file is to be opened, according to the <a href="../io_flags.html#mode_flags">io stream mode flag</a>s. The optional <em>filename</em> specifies the file to be opened and associated with the stream.</p> <p>Input and output file streams can be used in a similar manner to C++ predefined I/O streams, cin and cout.</p> <div class="related-examples-format"> Example code: </div> <div class="related-examples"> <p>The following code reads input data and appends the result to an output file.</p> <pre class="example-code"> ifstream fin( "/tmp/data.txt" ); ofstream fout( "/tmp/results.txt", ios::app ); while( fin >> temp ) fout << temp + 2 << endl; fin.close(); fout.close(); </pre> </div> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="close.html">close</a><br> <a href="open.html">open</a> </div> </div> </td> </tr> </table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -