Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C++
Reference
Libraries Reference
<fstream>
Classes
Collapse All/Expand All Collapse All
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 Class 

Describes an object that controls insertion of elements and encoded objects into a stream buffer of class basic_filebuf<Elem, Tr>, with elements of type Elem, whose character traits are determined by the class Tr.

For a list of all members of this type, see basic_ofstream Members.

template <class Elem, class Tr = char_traits<Elem> >
    class basic_ofstream : public basic_ostream<Elem, Tr>

Parameters

Elem

The basic element of the file buffer.

Tr

The traits of the basic element of the file buffer (usually char_traits<Elem>).

When the wchar_t specialization of basic_ofstream writes to the file, if the file is opened in text mode it will write a MBCS sequence. The internal representation will use a buffer of wchar_t characters.

The object stores an object of class basic_filebuf<Elem, Tr>.

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

// basic_ofstream_class.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
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker