Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C++
Reference
Libraries Reference
<fstream>
Classes
Member Functions
 basic_ofstream::basic_ofstream
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
Standard C++ Library Reference 
basic_ofstream::basic_ofstream 

Creates an object of type basic_ofstream.

basic_ofstream( );
explicit basic_ofstream(
    const char *_Filename,
    ios_base::openmode _Mode = ios_base::out,
    int _Prot = (int)ios_base::_Openprot
);
explicit basic_ofstream(
    const wchar_t *_Filename,
    ios_base::openmode _Mode = ios_base::out,
    int _Prot = (int)ios_base::_Openprot
);

Parameters

_Filename

The name of the file to open.

_Mode

One of the enumerations in ios_base::openmode.

_Prot

The default file opening protection.

The first constructor initializes the base class by calling basic_ostream(sb), where sb is the stored object of class basic_filebuf<Elem, Tr>. It also initializes sb by calling basic_filebuf<Elem, Tr>.

The second and third constructors initializes the base class by calling basic_ostream(sb). It also initializes sb by calling basic_filebuf<Elem, Tr> and then sb.open(_Filename, _Mode | ios_base::out). If the latter function returns a null pointer, the constructor calls setstate(failbit).

The following example shows how to create a basic_ofstream object and write text to it.

// basic_ofstream_ctor.cpp
// compile with: /EHsc
#include <fstream>

using namespace std;

int main(int argc, char **argv)
{
    ofstream ofs("C:\\ofstream.txt");
    if (!ofs.bad())
    {
        ofs << "Writing to a basic_ofstream object..." << endl;
        ofs.close();
    }
}

Header: <fstream>

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker