libstdc++
std::basic_ofstream Class Reference
Inheritance diagram for std::basic_ofstream:

List of all members.

Public Types

Public Member Functions

Arithmetic Inserters

All the operator<< functions (aka formatted output functions) have some common behavior. Each starts by constructing a temporary object of type std::basic_ostream::sentry. This can have several effects, concluding with the setting of a status flag; see the sentry documentation for more.

If the sentry status is good, the function tries to generate whatever data is appropriate for the type of the argument.

If an exception is thrown during insertion, ios_base::badbit will be turned on in the stream's error state without causing an ios_base::failure to be thrown. The original exception will then be rethrown.

Unformatted Output Functions

All the unformatted output functions have some common behavior. Each starts by constructing a temporary object of type std::basic_ostream::sentry. This has several effects, concluding with the setting of a status flag; see the sentry documentation for more.

If the sentry status is good, the function tries to generate whatever data is appropriate for the type of the argument.

If an exception is thrown during insertion, ios_base::badbit will be turned on in the stream's error state. If badbit is on in the stream's exceptions mask, the exception will be rethrown without completing its actions.

Protected Member Functions

Friends


Detailed Description

Controlling output for files.

This class supports reading from named files, using the inherited functions from std::basic_ostream. To control the associated sequence, an instance of std::basic_filebuf is used, which this page refers to as sb.


Constructor & Destructor Documentation

std::basic_ofstream::basic_ofstream ( ) [inline]

Default constructor.

Initializes sb using its default constructor, and passes &sb to the base class initializer. Does not open any files (you haven't given it a filename to open).

Definition at line 614 of file fstream.

std::basic_ofstream::basic_ofstream ( const char *  __s,
ios_base::openmode  __mode = ios_base::out|ios_base::trunc 
) [inline, explicit]

Create an output file stream.

Parameters:
sNull terminated string specifying the filename.
modeOpen file in specified mode (see std::ios_base).

ios_base::out|ios_base::trunc is automatically included in mode.

Tip: When using std::string to hold the filename, you must use .c_str() before passing it to this constructor.

Definition at line 629 of file fstream.

References open().

std::basic_ofstream::basic_ofstream ( const std::string __s,
ios_base::openmode  __mode = ios_base::out|ios_base::trunc 
) [inline, explicit]

Create an output file stream.

Parameters:
sstd::string specifying the filename.
modeOpen file in specified mode (see std::ios_base).

ios_base::out|ios_base::trunc is automatically included in mode.

Definition at line 647 of file fstream.

References open().

std::basic_ofstream::~basic_ofstream ( ) [inline]

The destructor does nothing.

The file is closed by the filebuf object, not the formatting stream.

Definition at line 662 of file fstream.


Member Function Documentation

void std::basic_ostream::_M_write ( const char_type __s,
streamsize  __n 
) [inline, inherited]

Simple insertion.

Parameters:
cThe character to insert.
Returns:
*this

Tries to insert c.

Note:
This function is not overloaded on signed char and unsigned char.

Definition at line 289 of file ostream.

void std::basic_ofstream::close ( ) [inline]

Close the file.

Calls std::basic_filebuf::close(). If that function fails, failbit is set in the stream's error state.

Definition at line 742 of file fstream.

References std::basic_filebuf::close(), and std::ios_base::failbit.

__ostream_type& std::basic_ostream::flush ( ) [inherited]

Synchronizing the stream buffer.

Returns:
*this

If rdbuf() is a null pointer, changes nothing.

Otherwise, calls rdbuf()->pubsync(), and if that returns -1, sets badbit.

bool std::basic_ofstream::is_open ( ) [inline]

Wrapper to test for an open file.

Returns:
rdbuf()->is_open()

Definition at line 681 of file fstream.

References std::basic_filebuf::is_open().

void std::basic_ofstream::open ( const char *  __s,
ios_base::openmode  __mode = ios_base::out | ios_base::trunc 
) [inline]

Opens an external file.

Parameters:
sThe name of the file.
modeThe open mode flags.

Calls std::basic_filebuf::open(s,mode|out|trunc). If that function fails, failbit is set in the stream's error state.

Tip: When using std::string to hold the filename, you must use .c_str() before passing it to this constructor.

Definition at line 702 of file fstream.

References std::basic_filebuf::open(), std::ios_base::out, and std::ios_base::failbit.

Referenced by basic_ofstream().

void std::basic_ofstream::open ( const std::string __s,
ios_base::openmode  __mode = ios_base::out | ios_base::trunc 
) [inline]

Opens an external file.

Parameters:
sThe name of the file.
modeThe open mode flags.

Calls std::basic_filebuf::open(s,mode|out|trunc). If that function fails, failbit is set in the stream's error state.

Definition at line 723 of file fstream.

References std::basic_filebuf::open(), std::ios_base::out, and std::ios_base::failbit.

__ostream_type& std::basic_ostream::operator<< ( __ostream_type &(*)(__ostream_type &)  __pf) [inline, inherited]

Interface for manipulators.

Manipulators such as std::endl and std::hex use these functions in constructs like "std::cout << std::endl". For more information, see the iomanip header.

Definition at line 110 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( __ios_type &(*)(__ios_type &)  __pf) [inline, inherited]

Interface for manipulators.

Manipulators such as std::endl and std::hex use these functions in constructs like "std::cout << std::endl". For more information, see the iomanip header.

Definition at line 119 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( ios_base &(*)(ios_base &)  __pf) [inline, inherited]

Interface for manipulators.

Manipulators such as std::endl and std::hex use these functions in constructs like "std::cout << std::endl". For more information, see the iomanip header.

Definition at line 129 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 167 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( unsigned long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 171 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( bool  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 175 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( short  __n) [inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

__ostream_type& std::basic_ostream::operator<< ( unsigned short  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 182 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( int  __n) [inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

__ostream_type& std::basic_ostream::operator<< ( unsigned int  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 193 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( long long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 202 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( unsigned long long  __n) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 206 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( double  __f) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 211 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( float  __f) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 215 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( long double  __f) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 223 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( const void *  __p) [inline, inherited]

Basic arithmetic inserters.

Parameters:
Avariable of builtin type.
Returns:
*this if successful

These functions use the stream's current locale (specifically, the num_get facet) to perform numeric formatting.

Definition at line 227 of file ostream.

__ostream_type& std::basic_ostream::operator<< ( __streambuf_type __sb) [inherited]

Extracting from another streambuf.

Parameters:
sbA pointer to a streambuf

This function behaves like one of the basic arithmetic extractors, in that it also constructs a sentry object and has the same error handling behavior.

If sb is NULL, the stream will set failbit in its error state.

Characters are extracted from sb and inserted into *this until one of the following occurs:

  • the input stream reaches end-of-file,
  • insertion into the output sequence fails (in this case, the character that would have been inserted is not extracted), or
  • an exception occurs while getting a character from sb, which sets failbit in the error state

If the function inserts no characters, failbit is set.

__ostream_type& std::basic_ostream::put ( char_type  __c) [inherited]

Simple insertion.

Parameters:
cThe character to insert.
Returns:
*this

Tries to insert c.

Note:
This function is not overloaded on signed char and unsigned char.
__filebuf_type* std::basic_ofstream::rdbuf ( ) const [inline]

Accessing the underlying buffer.

Returns:
The current basic_filebuf buffer.

This hides both signatures of std::basic_ios::rdbuf().

Definition at line 673 of file fstream.

__ostream_type& std::basic_ostream::seekp ( pos_type  ) [inherited]

Changing the current write position.

Parameters:
posA file position object.
Returns:
*this

If fail() is not true, calls rdbuf()->pubseekpos(pos). If that function fails, sets failbit.

__ostream_type& std::basic_ostream::seekp ( off_type  ,
ios_base::seekdir   
) [inherited]

Changing the current write position.

Parameters:
offA file offset object.
dirThe direction in which to seek.
Returns:
*this

If fail() is not true, calls rdbuf()->pubseekoff(off,dir). If that function fails, sets failbit.

pos_type std::basic_ostream::tellp ( ) [inherited]

Getting the current write position.

Returns:
A file position object.

If fail() is not false, returns pos_type(-1) to indicate failure. Otherwise returns rdbuf()->pubseekoff(0,cur,out).

__ostream_type& std::basic_ostream::write ( const char_type __s,
streamsize  __n 
) [inherited]

Character string insertion.

Parameters:
sThe array to insert.
nMaximum number of characters to insert.
Returns:
*this

Characters are copied from s and inserted into the stream until one of the following happens:

  • n characters are inserted
  • inserting into the output sequence fails (in this case, badbit will be set in the stream's error state)
Note:
This function is not overloaded on signed char and unsigned char.

The documentation for this class was generated from the following file: