std::ios_base::openmode
From cppreference.com
| typedef /* 実装定義 */ openmode; |
||
| static constexpr openmode app = /* 実装定義 */; static constexpr openmode binary = /* 実装定義 */; |
||
| static constexpr openmode noreplace = /* 実装定義 */; |
(C++23から) | |
利用可能なファイルオープンフラグを指定します。これはBitmaskTypeであり、以下の定数が定義されています。
| Constant | 説明 |
| app | 書き込みごとにストリームの末尾にシークします。 |
| 2進 | バイナリモードで開きます。 |
| in | 読み取り用に開きます。 |
| out | 書き込み用に開きます。 |
| trunc | 開くときにストリームの内容を破棄します。 |
| ate | 開いてすぐにストリームの末尾にシークします。 |
| noreplace (C++23) | 排他モードで開きます。 |
[編集] 例
このコードを実行
#include <fstream> #include <iostream> #include <string> int main() { const char* fname = "unique_name.txt"; // write to a temporary stream object 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> の public メンバ関数) |