std::basic_fstream::basic_fstream
来自cppreference.com
< cpp | io | basic fstream
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| 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) | |
构建新的文件流.
Original:
Constructs new file stream.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
默认的构造方法:构造一个流,不与文件关联的默认构造std::basic_filebuf和构造的基本与默认构造std::basic_filebuf成员的指针.
Original:
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.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
首先,作为默认的构造函数执行相同的步骤,,然后asssociate流文件的调用rdbuf()->open(filename, mode).。如果open()调用返回一个空指针,设置setstate(failbit).
Original:
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).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
同basic_fstream(filename.c_str(), mode).
Original:
Same as basic_fstream(filename.c_str(), mode).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
4)
移动的构造函数。首先,将构建
other(不影响rdbuf()指针)的基类,然后将构建std::basic_filebuf成员,然后调用this->set_rdbuf()安装新的basic_filebufrdbuf()在基类的指针.Original:
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.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
5)
拷贝构造函数被删除:这个类是不是复制的.
Original:
The copy-constructor is deleted: this class is not copyable.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[编辑] 参数
| filename | - | 被打开的文件的名称
Original: the name of the file to be opened The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mode | - | 指定流的开放模式。这是位掩码类型,有以下常量的定义:
Original: specifies stream open mode. It is bitmask type, the following constants are defined:
The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| other | - | 另一个文件流作为源使用
Original: another file stream to use as source The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[编辑] 为例
#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)); }
[编辑] 另请参阅
| 打开一个文件,并将它与数据流 Original: opens a file and associates it with the stream The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数) | |
| 打开一个文件,并将其配置为相应的字符序列 Original: opens a file and configures it as the associated character sequence The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数of std::basic_filebuf)
| |
| 取代了 rdbuf不清除其错误状态Original: replaces the rdbuf without clearing its error stateThe text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (受保护的成员函数) | |
| 构造对象 Original: constructs the object The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (公共成员函数of std::basic_iostream)
| |