std::basic_fstream::basic_fstream
来自cppreference.com
< cpp | io | basic fstream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
basic_fstream(); |
(1) | |
basic_fstream( const char* filename, ios_base::openmode mode = ios_base::in|ios_base::out ); |
(2) | |
basic_fstream( const string& filename, ios_base::openmode mode = ios_base::in|ios_base::out ); |
(3) | (C++11 起) |
basic_fstream( basic_fstream&& other ); |
(4) | (C++11 起) |
basic_fstream( const basic_fstream& rhs) = delete; |
(5) | |
构建新的文件流.
1)
默认的构造方法:构造一个流,不与文件关联的默认构造std::basic_filebuf和构造的基本与默认构造std::basic_filebuf成员的指针.
原文:
Default constructor: constructs a stream that is not associated with a file: default-constructs the std::basic_filebuf and constructs the base with the pointer to this default-constructed std::basic_filebuf member.
2)
首先,作为默认的构造函数执行相同的步骤,,然后asssociate流文件的调用rdbuf()->open(filename, mode).。如果open()调用返回一个空指针,设置setstate(failbit).
原文:
First, performs the same steps as the default constructor, then asssociate the stream with a file by calling rdbuf()->open(filename, mode).. If the open() call returns a null pointer, sets setstate(failbit).
3)
同basic_fstream(filename.c_str(), mode).
原文:
Same as basic_fstream(filename.c_str(), mode).
4)
移动的构造函数。首先,将构建
other
(不影响rdbuf()
指针)的基类,然后将构建std::basic_filebuf成员,然后调用this->set_rdbuf()安装新的basic_filebuf
rdbuf()在基类的指针.原文:
Move constructor. First, move-constructs the base class from
other
(which does not affect the rdbuf()
pointer), then move-constructs the std::basic_filebuf member, then calls this->set_rdbuf() to install the new basic_filebuf
as the rdbuf() pointer in the base class.5)
拷贝构造函数被删除:这个类是不是复制的.
原文:
The copy-constructor is deleted: this class is not copyable.
[编辑] 参数
filename | - | 被打开的文件的名称
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mode | - | 指定流的开放模式。这是位掩码类型,有以下常量的定义:
原文: specifies stream open mode. It is bitmask type, the following constants are defined:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
other | - | 另一个文件流作为源使用
原文: another file stream to use as source |
[编辑] 为例
#include <fstream> #include <utility> #include <string> 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)); }
[编辑] 另请参阅
打开一个文件,并将它与数据流 原文: opens a file and associates it with the stream (公共成员函数) | |
打开一个文件,并将其配置为相应的字符序列 原文: opens a file and configures it as the associated character sequence (公共成员函数of std::basic_filebuf )
| |
取代了 rdbuf 不清除其错误状态原文: replaces the rdbuf without clearing its error state(受保护的成员函数) | |
构造对象 (公共成员函数of std::basic_iostream )
|