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

📄 ofstream.htm

📁 使用C++开发过程中
💻 HTM
字号:
<html>
<head>
<title> The basic_ofstream(ofstream) Class</title>
</head>

<body bgcolor="#FFFFFF">

<img src="ofstrban.gif">

<pre>
<font size=5>Class Name</font>            basic_ofstream

<font size=5>Header File</font>           &lt;fstream&gt;

<font size=5>Classification</font>      Input/Output (Format Class)
</pre>
<a href="ofstream.htm#diagram">Class Relationship Diagram</a><br>
<br>
<a href="ofstream.htm#desc">Class Description</a><br>
<h1>Member Classes</h1>


<a href="filebuf.htm">basic_filebuf</a>

<h1>Methods</h1> 
<pre>
<a href="ofstream.htm#ofstream1">basic_ofstream()</a><br>
<a href="ofstream.htm#ofstream2">explicit basic_ofstream(const char* s,ios_base::openmode mode = ios_base::in)</a><br>
<a href="ofstream.htm#rdbuf">basic_filebuf&lt;charT,traits&gt;* rdbuf() const</a><br>
<a href="filebuf.htm#isopen">bool is_open()</a><br>
<a href="filebuf.htm#open">void open(const char* Str, openmode OMode = in)</a><br>
<a href="filebuf.htm#close">void close()</a><br>
</pre>

<a href="ofstream.htm#example"><h2>Example</h2></a><br>
<hr>
<a name="desc"><h3>Class Description</h3></a>
<p>
The ofstream class is derived from the basic_istream class. The ofstream class models the output
file stream. Whereas the basic_istream class focuses on a input stream normally attached to the
console, the ifstream focuses on a stream normally attached to a file.  The ofstream is a 
specialized basic_ostream class. Through the filebuf component the ifstream class has access to
the file.  It is important to note that the ANSI/ISO standard for the iostreams does not support
the concept of a file descriptor.  Older implementations of the iostreams often included file 
descriptor access through the filebuf class and some type of fd( ) method.  This  type of access
is no longer supported. The standard typedef for basic_ofstream is <i>ofstream</i>.
</p>                      
<hr>


<pre>                                
<a name="ofstream1">Method            basic_ofstream()</a>

Access            Public

Classification    Constructor

Syntax            basic_ofstream()

Parameters        None

Return            None

</pre>

<h3>Description</h3>       
<p>

This basic_ofstream() method constructs a basic_ifstream object. It constructs a
stream that is not connected to any file or device. The open() method will have to
be called to connect the stream with a file or device.
</p>
<hr>


<pre>                                
<a name="ofstream2">Method            basic_ofstream()</a>

Access            Public

Classification    Constructor

Syntax            explicit basic_ofstream(const char* Str,ios_base::openmode OMode = ios_base::in)

Parameters        Str points to the name of the file or device that will be opened and
                  connected to the ofstream object. OMode is the mode the stream will
                  be opened in.

Return            None

</pre>

<h3>Description</h3>       
<p>

This basic_ofstream() method constructs a basic_ofstream object. This constructor constructs a
stream that will be connected to the device named by Str.  The device or file will be opened 
in the mode specified by OMode.  This constructor opens the file specified by Str. 
if the file cannot be opened the buffer state will contain the error condition.
</p>
<hr>

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

Access            Public

Classification    Accessor

Syntax            basic_filebuf&lt;charT,traits&gt;* rdbuf() const

Parameters        None

Return            Returns a pointer to the associated streambuf object.

</pre>

<h3>Description</h3>       
<p>
The rdbuf() method returns a pointer to the associated streambuf object.
</p>
<hr>

<p>
<a name="diagram"><h2>The Class Relationship Diagram of basic_ofstream</h2></a>
<img src="ofstream.gif">
</p>
<hr>

<a name="example"></a>
<img src="lego.gif">

<pre>
// This program uses the ofstream class to
// generate a simple HTML skeleton
// that can be opened with a web browser.

#include &lt;iostream&gt;
#include &lt;fstream&gt;


using namespace std;

void main(void)
{

   ofstream Internet("WebPage.html");
   Internet &lt;&lt; "&lt;html&gt;" &lt;&lt; endl &lt;&lt; "&lt;head&gt;" &lt;&lt; endl;
   Internet &lt;&lt; "&lt;title&gt;C++ Standard Class Library&lt;/title&gt;" &lt;&lt; endl;
   Internet &lt;&lt; "&lt;/head&gt;" &lt;&lt; endl &lt;&lt; "&lt;body&gt;" &lt;&lt; endl;
   Internet &lt;&lt; "&lt;h3&gt;Object Oriented I/O&lt;/h3&gt;" &lt;&lt; endl;
   Internet &lt;&lt; "The iostreams can be used to generate HTML files!" &lt;&lt; endl;
   Internet &lt;&lt; "and Web pages" &lt;&lt;endl;
   Internet &lt;&lt; "&lt;/body&gt;" &lt;&lt; endl &lt;&lt; "&lt;/html&gt;" &lt;&lt; endl;
   Internet.close();
}

</pre>


</body>
</html>



⌨️ 快捷键说明

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