namespace std { template <class charT, class traits = char_traits<charT>> class basic_ofstream : public basic_ostream<charT, traits> { public: using char_type = charT; using int_type = typename traits::int_type; using pos_type = typename traits::pos_type; using off_type = typename traits::off_type; using traits_type = traits; // [ofstream.cons], constructors basic_ofstream(); explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); explicit basic_ofstream(const filesystem::path::value_type* s, ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn] explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); explicit basic_ofstream(const filesystem::path& s, ios_base::openmode mode = ios_base::out); basic_ofstream(const basic_ofstream& rhs) = delete; basic_ofstream(basic_ofstream&& rhs); // [ofstream.assign], assign and swap basic_ofstream& operator=(const basic_ofstream& rhs) = delete; basic_ofstream& operator=(basic_ofstream&& rhs); void swap(basic_ofstream& rhs); // [ofstream.members], members basic_filebuf<charT, traits>* rdbuf() const; bool is_open() const; void open(const char* s, ios_base::openmode mode = ios_base::out); void open(const filesystem::path::value_type* s, ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn] void open(const string& s, ios_base::openmode mode = ios_base::out); void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out); void close(); private: basic_filebuf<charT, traits> sb; // exposition only }; template <class charT, class traits> void swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y); }
Класс basic_ofstream<charT, traits> поддерживает запись в именованные файлы. Он использует basic_filebuf<charT, traits> объект для управления связанной последовательностью. Для демонстрации поддерживаемые данные представлены здесь как:
sb, filebuf объект.
basic_ofstream();
Effects: Создает объект класса basic_ofstream<charT, traits>, инициализируя базовый класс с помощью basic_ostream(&sb) и инициализируя sb с помощью basic_filebuf<charT, traits>()) ([ostream.cons], [filebuf.cons]).
explicit basic_ofstream(const char* s,
ios_base::openmode mode = ios_base::out);
explicit basic_ofstream(const filesystem::path::value_type* s,
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
Effects: Создает объект класса basic_ofstream<charT, traits>, инициализируя базовый класс с помощью basic_ostream(&sb) и инициализируя sb с помощью basic_filebuf<charT, traits>()) ([ostream.cons], [filebuf.cons]), затем вызывает rdbuf()->open(s, mode | ios_base::out). Если эта функция возвращает нулевой указатель, вызывает setstate(failbit).
explicit basic_ofstream(const string& s,
ios_base::openmode mode = ios_base::out);
explicit basic_ofstream(const filesystem::path& s,
ios_base::openmode mode = ios_base::out);
basic_ofstream(basic_ofstream&& rhs);
basic_ofstream& operator=(basic_ofstream&& rhs);
void swap(basic_ofstream& rhs);
Effects: Меняет состояние *this и rhs по вызову basic_ostream<charT, traits>::swap(rhs) и sb.swap(rhs.sb).
template <class charT, class traits>
void swap(basic_ofstream<charT, traits>& x,
basic_ofstream<charT, traits>& y);
basic_filebuf<charT, traits>* rdbuf() const;
bool is_open() const;
void open(const char* s, ios_base::openmode mode = ios_base::out);
void open(const filesystem::path::value_type* s,
ios_base::openmode mode = ios_base::out); // wide systems only; see [fstream.syn]
Effects: Звонки rdbuf()->open(s, mode | ios_base::out). Если эта функция не возвращает вызовы нулевого указателя clear(), в противном случае вызывает setstate(failbit) (который может вызывать ios_base::failure) ([iostate.flags]).
void close();
Effects: Вызывает rdbuf()->close() и, если эта функция дает сбой (возвращает нулевой указатель), вызывает setstate(failbit) (который может вызывать ios_base::failure) ([iostate.flags]).
void open(const string& s, ios_base::openmode mode = ios_base::out);
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::out);