std::ios_base::openmode(3)
π NAME
Okay bestie, welcome to std::ios_base::openmode(3) β the page from the C++ Standard Libary manual. The name section is literally std::ios_base::openmode - std::ios_base::openmode, and honestly? iconic repetitive queen behavior π
.
β¨ Synopsis
Here's the whole typedef-and-constants situation, copied exactly so you can trust it:
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 ate = /* implementation defined */;
static constexpr openmode noreplace = /* implementation defined */;
(since C++23)
So openmode is a type that specifies the available file open flags. It's a BitmaskType, and the following constants are defined β no cap:
appβ seek to the end of stream before each writebinaryβ open in binary modeinβ open for readingoutβ open for writingtruncβ discard the contents of the stream when openingateβ seek to the end of stream immediately after opennoreplaceβ open in exclusive mode; this one is(since C++23)so it's the shiny new-ish bestie on the block β¨
π Example
The page literally says // Run this code right before this, so here is the exact example:
#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
π¦ See also
openβ opens a file and configures it as the associated character sequence (public member function ofstd::basic_filebuf<CharT,Traits>)constructorβ constructs abasic_stringbufobject (public member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)
Cute lil sign-off: this page came from source http://cppreference.com, version/date 2024.06.10, and it's the std::ios_base::openmode(3) page. Bye bestie, go open some streams responsibly π«Άπ
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms