Namespaces
Variants

std::ios_base:: openmode

From cppreference.net
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 */ ;
(seit C++23)

Legt verfügbare Dateiöffnungsflags fest. Es ist ein BitmaskType , die folgenden Konstanten sind definiert:

Konstante Erklärung
app Positioniere vor jedem Schreibvorgang ans Ende des Streams
binary Öffne im Binärmodus
in Öffne zum Lesen
out Öffne zum Schreiben
trunc Verwerfe die Stream-Inhalte beim Öffnen
ate Positioniere unmittelbar nach dem Öffnen ans Ende des Streams
noreplace (C++23) Öffne im exklusiven Modus

Beispiel

#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';
}

Ausgabe:

Hi

Siehe auch

öffnet eine Datei und konfiguriert sie als zugehörige Zeichensequenz
(öffentliche Elementfunktion von std::basic_filebuf<CharT,Traits> )
konstruiert ein basic_stringbuf Objekt
(öffentliche Elementfunktion von std::basic_stringbuf<CharT,Traits,Allocator> )