std::basic_ofstream

来自cppreference.com
< cpp | io
在标头 <fstream> 定义
template< 
    class CharT, 
    class Traits = std::char_traits<CharT>
> class basic_ofstream : public std::basic_ostream<CharT, Traits>

类模板 basic_ofstream 实现文件上基于流的高层输出操作。它将 std::basic_ostream 的高层接口赋予基于文件的流缓冲(std::basic_filebuf)。

std::basic_ofstream 的典型实现只保有一个非派生成员:一个 std::basic_filebuf<CharT, Traits> 的实例。

cpp/io/ios basecpp/io/basic ioscpp/io/basic ostream

继承图

提供了几个针对常用字符类型的 typedef:

在标头 <fstream> 定义
类型 定义
std::ofstream std::basic_ofstream<char>
std::wofstream std::basic_ofstream<wchar_t>

成员类型

成员类型 定义
char_type CharT[编辑]
traits_type TraitsTraits::char_type 不是 CharT 时程序非良构。[编辑]
int_type Traits::int_type[编辑]
pos_type Traits::pos_type[编辑]
off_type Traits::off_type[编辑]

成员函数

构造文件流
(公开成员函数) [编辑]
(析构函数)
[虚] (隐式声明)
析构 basic_ofstream 和关联的缓冲区,并关闭文件
(虚公开成员函数) [编辑]
(C++11)
移动文件流
(公开成员函数) [编辑]
(C++11)
交换两个文件流
(公开成员函数) [编辑]
返回底层未处理的文件设备对象
(公开成员函数) [编辑]
返回底层的由实现定义的句柄
(公开成员函数) [编辑]
文件操作
检查流是否有关联文件
(公开成员函数) [编辑]
打开文件,并将它与流关联
(公开成员函数) [编辑]
关闭关联文件
(公开成员函数) [编辑]

非成员函数

特化 std::swap 算法
(函数模板) [编辑]

继承自 std::basic_ostream

成员函数

有格式输出
插入带格式数据
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
无格式输出
插入字符
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
按区块插入字符
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
寻位
返回输出位置指示器
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
设置输出位置指示器
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]
杂项
与底层存储设备同步
(std::basic_ostream<CharT,Traits> 的公开成员函数) [编辑]

成员类

为输出操作实现流准备的基本逻辑
(std::basic_ostream<CharT,Traits> 的公开成员类) [编辑]

继承自 std::basic_ios

成员类型

成员类型 定义
char_type CharT
traits_type Traits
int_type Traits::int_type
pos_type Traits::pos_type
off_type Traits::off_type

成员函数

状态函数