std::basic_fstream<CharT,Traits>::basic_fstream
提供: cppreference.com
basic_fstream(); |
(1) | |
explicit basic_fstream( const char* filename, {{#pad:|13}} std::ios_base::openmode mode = ios_base::in|ios_base::out ); |
(2) | |
explicit basic_fstream( const std::filesystem::path::value_type* filename, {{#pad:|13}} std::ios_base::openmode mode = ios_base::in|ios_base::out ); |
(3) | (C++17以上) |
explicit basic_fstream( const std::string& filename, {{#pad:|13}} std::ios_base::openmode mode = ios_base::in|ios_base::out ); |
(4) | (C++11以上) |
explicit basic_fstream( const std::filesystem::path& filename, {{#pad:|13}} std::ios_base::openmode mode = ios_base::in|ios_base::out ); |
(5) | (C++17以上) |
basic_fstream( basic_fstream&& other ); |
(6) | (C++11以上) |
basic_fstream( const basic_fstream& rhs) = delete; |
(7) | (C++11以上) |
新しいファイルストリームを構築します。
1) デフォルトコンストラクタ。 ファイルと紐付けられていないストリームを構築します。 std::basic_filebuf をデフォルト構築し、このデフォルト構築された std::basic_filebuf メンバへのポインタを使用して基底を構築します。
2-3) まず、デフォルトコンストラクタと同じステップを行います。 その後、
rdbuf()->open(filename, mode) を呼ぶことによって、ストリームをファイルと紐付けます (呼び出しの効果の詳細は std::basic_filebuf::open を参照してください)。 open() の呼び出しがヌルポインタを返した場合は、 setstate(failbit) をセットします。 オーバーロード (3) は、 std::filesystem::path::value_type が char でない場合にのみ提供されます。 (C++17以上)4-5)
basic_fstream(filename.c_str(), mode) と同じです。 6) ムーブコンストラクタ。 まず、
other から基底クラスをムーブ構築し (これは rdbuf() のポインタに影響を与えません)、その後、 std::basic_filebuf をムーブ構築し、その後、基底クラスの rdbuf() ポインタとして新しい basic_filebuf を設定するために this->set_rdbuf() を呼びます。7) コピーコンストラクタは削除されています。 このクラスはコピー可能ではありません。
引数
| filename | - | 開くファイルの名前 | ||||||||||||||
| mode | - | ストリームのオープンモードを指定します。 以下の定数が定義されています。
| ||||||||||||||
| other | - | ソースとして使用する別のファイルストリーム |
例
Run this code
#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));
}
関連項目
| ファイルを開き、それをストリームと紐付けます (パブリックメンバ関数) | |
| ファイルを開き、それを文字シーケンスとして紐付けます ( std::basic_filebuf<CharT,Traits>のパブリックメンバ関数)
| |
エラー状態をクリアせずに rdbuf を置き換えます (プロテクテッドメンバ関数) | |
| オブジェクトを構築します ( std::basic_iostream<CharT,Traits>のパブリックメンバ関数)
|