Difference between revisions of "cpp/io/ios base/openmode"
From cppreference.com
Fbuontempo (Talk | contribs) m (Added a tiny example) |
Fbuontempo (Talk | contribs) m (Changed file name to txt cos it wasn't in bin mode) |
||
Line 29: | Line 29: | ||
int main() | int main() | ||
{ | { | ||
− | std::ofstream f("test. | + | std::ofstream f("test.txt", std::ios::out {{!}} std::ios::app); |
f << "Hi\n"; | f << "Hi\n"; | ||
} | } |
Revision as of 02:27, 15 May 2023
typedef /*implementation defined*/ openmode; |
||
static constexpr openmode app = /*implementation defined*/ static constexpr openmode binary = /*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 |
Example
Run this code
#include <fstream> int main() { std::ofstream f("test.txt", std::ios::out | std::ios::app); f << "Hi\n"; }
See also
opens a file and configures it as the associated character sequence (public member function of std::basic_filebuf<CharT,Traits> )
| |
constructs a basic_stringbuf object (public member function of std::basic_stringbuf<CharT,Traits,Allocator> )
|