ios_base::openmode

Describes how to interact with a stream.

namespace std {
   class ios_base {
   public:
      typedef implementation-defined-bitmask-type iostate;
      static const iostate badbit;
      static const iostate eofbit;
      static const iostate failbit;
      static const iostate goodbit;
      ...
   };
}

Remarks

The type is a bitmask type that describes an object that can store the opening mode for several iostreams objects. The distinct flag values (elements) are:

  • app, to seek to the end of a stream before each insertion.

  • ate, to seek to the end of a stream when its controlling object is first created.

  • binary, to read a file as a binary stream, rather than as a text stream.

  • in, to permit extraction from a stream.

  • out, to permit insertion to a stream.

  • trunc, to delete contents of an existing file when its controlling object is created.

Example

// ios_base_openmode.cpp
// compile with: /EHsc
#include <iostream>
#include <fstream>

int main ( ) 
{
   using namespace std;
   fstream file;
   file.open( "rm.txt", ios_base::out | ios_base::trunc );

   file << "testing";
}

Requirements

Header: <ios>

Namespace: std

See Also

Reference

ios_base Class

iostream Programming

iostreams Conventions