📄 ofstream.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> <fstream>
<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<charT,traits>* 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<charT,traits>* 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 <iostream>
#include <fstream>
using namespace std;
void main(void)
{
ofstream Internet("WebPage.html");
Internet << "<html>" << endl << "<head>" << endl;
Internet << "<title>C++ Standard Class Library</title>" << endl;
Internet << "</head>" << endl << "<body>" << endl;
Internet << "<h3>Object Oriented I/O</h3>" << endl;
Internet << "The iostreams can be used to generate HTML files!" << endl;
Internet << "and Web pages" <<endl;
Internet << "</body>" << endl << "</html>" << endl;
Internet.close();
}
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -