std::ios_base::openmode
From cppreference.com
 
 
 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
Input/output library 
 
 
 
 
 
 
 
 
 
 
 
 
 Print functions (C++23)
 Buffers
(C++23)
(C++98/26*)
(C++20)
 Streams
 Abstractions
 File I/O
 String I/O
 Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
 Synchronized Output
(C++20)
 Types
 Error category interface
(C++11)
(C++11)
std::ios_base 
 
 Member functions
 Formatting
 Locales
 Internal extensible array
 Miscellaneous
 Member classes
 Member types
ios_base::openmode
typedef /* implementation defined */ openmode;
 
 
static constexpr openmode app       = /* implementation defined */;
 
 
static constexpr openmode binary    = /* implementation defined */;
static constexpr openmode in        = /* implementation defined */;
static constexpr openmode out       = /* implementation defined */;
static constexpr openmode trunc     = /* implementation defined */;
static constexpr openmode noreplace = /* implementation defined */;
 
 (since C++23) 
Specifies available file open flags. It is a BitmaskType, the following constants are defined:
 Constant
 Explanation
 app
 seek to the end of stream before each write
 binary
 open in binary mode
 in
 open for reading
 out
 open for writing
 trunc
 discard the contents of the stream when opening
 ate
 seek to the end of stream immediately after open
 noreplace (C++23)
 open in exclusive mode
[edit] Example
Run this code
#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'; }
Output:
Hi
[edit] See also
 
 opens a file and configures it as the associated character sequence 
(public member function of
(public member function of
std::basic_filebuf<CharT,Traits>) [edit] 
 
 constructs a 
(public member function of
basic_stringbuf object (public member function of
std::basic_stringbuf<CharT,Traits,Allocator>) [edit]