std::ios_base:: openmode
|
typedef
/* implementation defined */
openmode
;
|
||
|
static
constexpr
openmode app
=
/* implementation defined */
;
static
constexpr
openmode binary
=
/* implementation defined */
;
|
||
|
static
constexpr
openmode noreplace
=
/* implementation defined */
;
|
(C++23以降) | |
利用可能なファイルオープンフラグを指定します。これは BitmaskType であり、以下の定数が定義されています:
| 定数 | 説明 |
| app | 各書き込み前にストリームの終端へシーク |
| binary | バイナリモード でオープン |
| in | 読み取り用にオープン |
| out | 書き込み用にオープン |
| trunc | オープン時にストリームの内容を破棄 |
| ate | オープン直後にストリームの終端へシーク |
| noreplace (C++23) | 排他モードでオープン |
例
#include <fstream> #include <iostream> #include <string> int main() { const char* fname = "unique_name.txt"; // 一時的なストリームオブジェクトへの書き込み std::fstream(fname, std::ios::out | std::ios::trunc) << "Hi"; std::string s; std::fstream(fname, std::ios::in) >> s; std::cout << s << '\n'; }
出力:
Hi
関連項目
|
ファイルを開き、関連付けられた文字シーケンスとして設定する
(
std::basic_filebuf<CharT,Traits>
の公開メンバ関数)
|
|
basic_stringbuf
オブジェクトを構築する
(
std::basic_stringbuf<CharT,Traits,Allocator>
の公開メンバ関数)
|