std::basic_ofstream<CharT,Traits>:: basic_ofstream
|
basic_ofstream
(
)
;
|
(1) | |
|
explicit
basic_ofstream
(
const
char
*
filename,
std::
ios_base
::
openmode
mode
|
(2) | |
|
explicit
basic_ofstream
(
const
std
::
filesystem
::
path
::
value_type
*
filename,
std::
ios_base
::
openmode
mode
|
(3) | (C++17以降) |
|
explicit
basic_ofstream
(
const
std::
string
&
filename,
std::
ios_base
::
openmode
mode
|
(4) | (C++11以降) |
|
template
<
class
FsPath
>
explicit
basic_ofstream
(
const
FsPath
&
filename,
|
(5) | (C++17以降) |
|
basic_ofstream
(
basic_ofstream
&&
other
)
;
|
(6) | (C++11以降) |
|
basic_ofstream
(
const
basic_ofstream
&
rhs
)
=
delete
;
|
(7) | (C++11以降) |
新しいファイルストリームを構築します。
open()
の呼び出しがnullポインタを返した場合、
setstate
(
failbit
)
を設定します。
オーバーロード
(3)
は
std
::
filesystem
::
path
::
value_type
が
char
でない場合にのみ提供されます。
(C++17以降)
FsPath
が
std::filesystem::path
である場合にのみオーバーロード解決に参加する。
(C++17以降)
デフォルトのモードが
out
であるにもかかわらず、その効果は
std::filebuf::open
で説明されている
out | trunc
の効果と同一であることに注意。
rdbuf()
ポインタに影響しない)、次に
std::basic_filebuf
メンバをムーブ構築し、その後
this
-
>
set_rdbuf
(
)
を呼び出して、新しい
basic_filebuf
を基底クラスの
rdbuf()
ポインタとして設定する。
目次 |
パラメータ
| filename | - | 開くファイルの名前 | ||||||||||||||||
| mode | - |
ストリームのオープンモードを指定。以下の定数とそれらのビット単位ORを使用可能:
|
||||||||||||||||
| other | - | ソースとして使用する別のファイルストリーム |
例
#include <fstream> #include <string> #include <utility> int main() { std::ofstream f0; std::ofstream f1("test.bin", std::ios::binary); std::string name = "example.txt"; std::ofstream f2(name); std::ofstream f3(std::move(f1)); }
不具合報告
以下の動作変更の欠陥報告書は、以前に公開されたC++規格に対して遡及的に適用されました。
| DR | 適用対象 | 公開時の動作 | 正しい動作 |
|---|---|---|---|
| LWG 3430 | C++17 | std::filesystem::path オーバーロードが望ましくない変換を引き起こした | テンプレート化することで回避 |
関連項目
|
ファイルを開き、ストリームに関連付ける
(公開メンバ関数) |
|
|
ファイルを開き、関連する文字シーケンスとして設定する
(
std::basic_filebuf<CharT,Traits>
の公開メンバ関数)
|
|
rdbuf
を置き換え、そのエラー状態をクリアしない
(保護メンバ関数) |
|
|
オブジェクトを構築する
(
std::basic_ostream<CharT,Traits>
の公開メンバ関数)
|