std::basic_fstream<CharT,Traits>:: basic_fstream
|
basic_fstream
(
)
;
|
(1) | |
|
explicit
basic_fstream
(
const
char
*
filename,
std::
ios_base
::
openmode
mode
|
(2) | |
|
explicit
basic_fstream
(
const
std
::
filesystem
::
path
::
value_type
*
filename,
std::
ios_base
::
openmode
mode
|
(3) | (自 C++17 起) |
|
explicit
basic_fstream
(
const
std::
string
&
filename,
std::
ios_base
::
openmode
mode
|
(4) | (自 C++11 起) |
|
template
<
class
FsPath
>
explicit
basic_fstream
(
const
FsPath
&
filename,
|
(5) | (自 C++17 起) |
|
basic_fstream
(
basic_fstream
&&
other
)
;
|
(6) | (自 C++11 起) |
|
basic_fstream
(
const
basic_fstream
&
rhs
)
=
delete
;
|
(7) | (自 C++11 起) |
构造新的文件流。
open()
调用返回空指针,则设置
setstate
(
failbit
)
。
仅当
std
::
filesystem
::
path
::
value_type
不是
char
时才提供重载
(3)
。
(C++17 起)
FsPath
为
std::filesystem::path
时参与重载决议。
(since C++17)
rdbuf()
指针),然后移动构造
std::basic_filebuf
成员,最后调用
this
-
>
set_rdbuf
(
)
将新的
basic_filebuf
安装为基类中的
rdbuf()
指针。
目录 |
参数
| filename | - | 要打开的文件名 | ||||||||||||||||
| mode | - |
指定流打开模式。可使用以下常量及其按位或组合:
|
||||||||||||||||
| other | - | 用作源的其他文件流 |
示例
#include <fstream> #include <string> #include <utility> int main() { std::fstream f0; std::fstream f1("test.bin", std::ios::binary); std::string name = "example.txt"; std::fstream f2(name); std::fstream f3(std::move(f1)); }
缺陷报告
以下行为变更缺陷报告被追溯应用于先前发布的C++标准。
| 缺陷报告 | 适用标准 | 发布时行为 | 正确行为 |
|---|---|---|---|
| LWG 460 | C++98 |
重载
(2)
中
mode
的默认参数
缺失(在 概要说明 中存在) |
已添加 |
| LWG 3430 | C++17 | std::filesystem::path 重载导致不必要的转换 | 通过将其设为模板来避免 |
另请参阅
|
打开文件并将其与流关联
(公开成员函数) |
|
|
打开文件并将其配置为关联的字符序列
(
std::basic_filebuf<CharT,Traits>
的公开成员函数)
|
|
在不清除错误状态的情况下替换
rdbuf
(受保护成员函数) |
|
|
构造对象
(
std::basic_iostream<CharT,Traits>
的公开成员函数)
|