Namespaces
Variants
Actions

std::basic_ofstream

From cppreference.com
< cpp‎ | io
 
 
 
 
Defined in header <fstream>
template<

    class CharT,
    class Traits = std::char_traits<CharT>

> class basic_ofstream : public std::basic_ostream<CharT, Traits>

The class template basic_ofstream implements high-level output operations on file based streams. It interfaces a file-based streambuffer (std::basic_filebuf) with the high-level interface of (std::basic_ostream).

A typical implementation of std::basic_ofstream holds only one non-derived data member: an instance of std::basic_filebuf<CharT, Traits>.

cpp/io/ios basecpp/io/basic ioscpp/io/basic ostreamstd-basic ofstream-inheritance.svg

Inheritance diagram

Several typedefs for common character types are provided:

Defined in header <fstream>
Type Definition
std::ofstream std::basic_ofstream<char>
std::wofstream std::basic_ofstream<wchar_t>

Contents

[edit] Member types

Member type Definition
char_type CharT[edit]
traits_type Traits; the program is ill-formed if Traits::char_type is not CharT.[edit]
int_type Traits::int_type[edit]
pos_type Traits::pos_type[edit]
off_type Traits::off_type[edit]
native_handle_type(C++26) implementation-defined type that is TriviallyCopyable and semiregular[edit]

[edit] Member functions

constructs the file stream
(public member function) [edit]
(destructor)
[virtual] (implicitly declared)
destructs the basic_ofstream and the associated buffer, closes the file
(virtual public member function) [edit]
(C++11)
moves the file stream
(public member function) [edit]
(C++11)
swaps two file streams
(public member function) [edit]
returns the underlying raw file device object
(public member function) [edit]
returns the underlying implementation-defined handle
(public member function) [edit]
File operations
checks if the stream has an associated file
(public member function) [edit]
opens a file and associates it with the stream
(public member function) [edit]
closes the associated file
(public member function) [edit]

[edit] Non-member functions

specializes the std::swap algorithm
(function template) [edit]

Inherited from std::basic_ostream

Member functions

Formatted output
inserts formatted data
(public member function of std::basic_ostream<CharT,Traits>) [edit]
Unformatted output