std::basic_ofstream< _CharT, _Traits >(3)

NAME
std::basic_ofstream< _CharT, _Traits > - Controlling output for files.

SYNOPSIS

Inherits std::basic_ostream< _CharT, _Traits >.

  Public Types
typedef ctype< _CharT > __ctype_type
typedef basic_filebuf< char_type, traits_type > __filebuf_type
typedef basic_ios< _CharT, _Traits > __ios_type
typedef num_put< _CharT, ostreambuf_iterator< _CharT, _Traits > > __num_put_type
typedef basic_ostream< char_type, traits_type > __ostream_type
typedef basic_streambuf< _CharT, _Traits > __streambuf_type
typedef _CharT char_type
typedef traits_type::int_type int_type
typedef traits_type::off_type off_type
typedef traits_type::pos_type pos_type
typedef _Traits traits_type

  Public Member Functions
basic_ofstream ()
Default constructor.
basic_ofstream (basic_ofstream &&__rhs)
basic_ofstream (const basic_ofstream &)=delete
basic_ofstream (const char *__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
basic_ofstream (const std::string &__s, ios_base::openmode __mode=ios_base::out)
Create an output file stream.
~basic_ofstream ()
The destructor does nothing.
template<typename _ValueT > basic_ostream< _CharT, _Traits > & _M_insert (_ValueT __v)
void close ()
Close the file.
bool is_open ()
Wrapper to test for an open file.
bool is_open () const
void open (const char *__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
void open (const std::string &__s, ios_base::openmode __mode=ios_base::out)
Opens an external file.
__ostream_type & operator<< (__ios_type &(*__pf)(__ios_type &))
__ostream_type & operator<< (__ostream_type &(*__pf)(__ostream_type &))
Interface for manipulators.
__ostream_type & operator<< (ios_base &(*__pf)(ios_base &))
basic_ofstream & operator= (basic_ofstream &&__rhs)
basic_ofstream & operator= (const basic_ofstream &)=delete
__filebuf_type * rdbuf () const
Accessing the underlying buffer.
void swap (basic_ofstream &__rhs)

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.

__ostream_type & operator<< (long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (bool __n)
Integer arithmetic inserters.
__ostream_type & operator<< (short __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned short __n)
Integer arithmetic inserters.
__ostream_type & operator<< (int __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned int __n)
Integer arithmetic inserters.
__ostream_type & operator<< (long long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned long long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (double __f)
Floating point arithmetic inserters.
__ostream_type & operator<< (float __f)
Integer arithmetic inserters.
__ostream_type & operator<< (long double __f)
Integer arithmetic inserters.
__ostream_type & operator<< (const void *__p)
Pointer arithmetic inserters.
__ostream_type & operator<< (__streambuf_type *__sb)
Extracting from another streambuf.

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.

__ostream_type & operator<< (long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (bool __n)
Integer arithmetic inserters.
__ostream_type & operator<< (short __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned short __n)
Integer arithmetic inserters.
__ostream_type & operator<< (int __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned int __n)
Integer arithmetic inserters.
__ostream_type & operator<< (long long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (unsigned long long __n)
Integer arithmetic inserters.
__ostream_type & operator<< (double __f)
Floating point arithmetic inserters.
__ostream_type & operator<< (float __f)
Integer arithmetic inserters.
__ostream_type & operator<< (long double __f)
Integer arithmetic inserters.
__ostream_type & operator<< (const void *__p)
Pointer arithmetic inserters.
__ostream_type & operator<< (__streambuf_type *__sb)
Extracting from another streambuf.

  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.
__ostream_type & put (char_type __c)
Simple insertion.
void _M_write (const char_type *__s, streamsize __n)
Core write functionality, without sentry.
__ostream_type & write (const char_type *__s, streamsize __n)
Character string insertion.
__ostream_type & flush ()
Synchronizing the stream buffer.
pos_type tellp ()
Getting the current write position.
__ostream_type & seekp (pos_type)
Changing the current write position.
__ostream_type & seekp (off_type, ios_base::seekdir)
Changing the current write position.
void swap (basic_ostream &__rhs)
Simple insertion.
template<typename _ValueT > __ostream_type & _M_insert (_ValueT __v)
Simple insertion.

Detailed Description

  template<typename _CharT, typename _Traits>
class std::basic_ofstream< _CharT, _Traits >" Controlling output for files.

Template Parameters
    _CharT Type of character stream.
    _Traits Traits for character type, defaults to char_traits<_CharT>.

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.

Definition at line 753 of file fstream.

Constructor & Destructor Documentation

  template<typename _CharT , typename _Traits > std::basic_ofstream< _CharT, _Traits >::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 779 of file fstream.

  template<typename _CharT , typename _Traits > std::basic_ofstream< _CharT, _Traits >::basic_ofstream (const char * __s, ios_base::openmode __mode = ios_base::out) [inline], [explicit]

Create an output file stream.

Parameters
    __s Null terminated string specifying the filename.
    __mode Open file in specified mode (see std::ios_base).

ios_base::out is automatically included in __mode.

Definition at line 790 of file fstream.

References std::basic_ofstream< _CharT, _Traits >::open().

  template<typename _CharT , typename _Traits > std::basic_ofstream< _CharT, _Traits >::basic_ofstream (const std::string & __s, ios_base::openmode __mode = ios_base::out) [inline], [explicit]

Create an output file stream.

Parameters
    __s std::string specifying the filename.
    __mode Open file in specified mode (see std::ios_base).

ios_base::out is automatically included in __mode.

Definition at line 825 of file fstream.

References std::basic_ofstream< _CharT, _Traits >::open().

  template<typename _CharT , typename _Traits > std::basic_ofstream< _CharT, _Traits >::~basic_ofstream () [inline]

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

Definition at line 862 of file fstream.

Member Function Documentation

  template<typename _CharT , typename _Traits > template<typename _ValueT > __ostream_type& std::basic_ostream< _CharT, _Traits >::_M_insert (_ValueT __v) [protected], [inherited]

Simple insertion.

Parameters
    __c The character to insert.

Returns
    *this

Tries to insert __c.

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

Referenced by std::basic_ostream< char >::operator<<().

  template<typename _CharT , typename _Traits > void std::basic_ostream< _CharT, _Traits >::_M_write (const char_type * __s, streamsize __n) [inline], [inherited]

Core write functionality, without sentry.

Parameters
    __s The array to insert.
    __n Maximum number of characters to insert.

Definition at line 317 of file ostream.

  template<typename _CharT , typename _Traits > void std::basic_ofstream< _CharT, _Traits >::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 993 of file fstream.

References std::basic_filebuf< _CharT, _Traits >::close(), and std::ios_base::failbit.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::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.

Definition at line 211 of file ostream.tcc.

Referenced by std::basic_ostream< _CharT, _Traits >::sentry::sentry().

  template<typename _CharT , typename _Traits > bool std::basic_ofstream< _CharT, _Traits >::is_open () [inline]

Wrapper to test for an open file.

Returns
    rdbuf()->is_open()

Definition at line 903 of file fstream.

References std::basic_filebuf< _CharT, _Traits >::is_open().

  template<typename _CharT , typename _Traits > void std::basic_ofstream< _CharT, _Traits >::open (const char * __s, ios_base::openmode __mode = ios_base::out) [inline]

Opens an external file.

Parameters
    __s The name of the file.
    __mode The open mode flags.

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

Definition at line 921 of file fstream.

References std::ios_base::failbit, std::basic_filebuf< _CharT, _Traits >::open(), and std::ios_base::out.

Referenced by std::basic_ofstream< _CharT, _Traits >::basic_ofstream().

  template<typename _CharT , typename _Traits > void std::basic_ofstream< _CharT, _Traits >::open (const std::string & __s, ios_base::openmode __mode = ios_base::out) [inline]

Opens an external file.

Parameters
    __s The name of the file.
    __mode The open mode flags.

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

Definition at line 960 of file fstream.

References std::ios_base::failbit, std::basic_filebuf< _CharT, _Traits >::open(), and std::ios_base::out.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::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 108 of file ostream.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::operator<< (__streambuf_type * __sb) [inherited]

Extracting from another streambuf.

Parameters
    __sb A 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.

Definition at line 120 of file ostream.tcc.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (bool __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 174 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (const void * __p) [inline], [inherited]

Pointer arithmetic inserters.

Parameters
    __p A variable of pointer 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 245 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (double __f) [inline], [inherited]

Floating point arithmetic inserters.

Parameters
    __f A variable of builtin floating point 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 220 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (float __f) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 224 of file ostream.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::operator<< (int __n) [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 106 of file ostream.tcc.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (long __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 166 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (long double __f) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 232 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (long long __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 201 of file ostream.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::operator<< (short __n) [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 92 of file ostream.tcc.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (unsigned int __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 192 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (unsigned long __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 170 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (unsigned long long __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 205 of file ostream.

  template<typename _CharT , typename _Traits > __ostream_type& std::basic_ostream< _CharT, _Traits >::operator<< (unsigned short __n) [inline], [inherited]

Integer arithmetic inserters.

Parameters
    __n A variable of builtin integral 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 181 of file ostream.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::put (char_type __c) [inherited]

Simple insertion.

Parameters
    __c The character to insert.

Returns
    *this

Tries to insert __c.

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

Definition at line 149 of file ostream.tcc.

  template<typename _CharT , typename _Traits > __filebuf_type* std::basic_ofstream< _CharT, _Traits >::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 895 of file fstream.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::seekp (off_type __off, ios_base::seekdir __dir) [inherited]

Changing the current write position.

Parameters
    __off A file offset object.
    __dir The direction in which to seek.

Returns
    *this

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

Definition at line 290 of file ostream.tcc.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::seekp (pos_type __pos) [inherited]

Changing the current write position.

Parameters
    __pos A file position object.

Returns
    *this

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

Definition at line 258 of file ostream.tcc.

  template<typename _CharT , typename _Traits > void std::basic_ostream< _CharT, _Traits >::swap (basic_ostream< _CharT, _Traits > & __rhs) [inline], [protected], [inherited]

Simple insertion.

Parameters
    __c The character to insert.

Returns
    *this

Tries to insert __c.

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

Definition at line 415 of file ostream.

Referenced by std::basic_ostream< char >::operator=().

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits >::pos_type std::basic_ostream< _CharT, _Traits >::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).

Definition at line 237 of file ostream.tcc.

  template<typename _CharT , typename _Traits > basic_ostream< _CharT, _Traits > & std::basic_ostream< _CharT, _Traits >::write (const char_type * __s, streamsize __n) [inherited]

Character string insertion.

Parameters
    __s The array to insert.
    __n Maximum 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.

Definition at line 183 of file ostream.tcc.

Author

Generated automatically by Doxygen for libstdc++ from the source code.