Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ios_base::openmode

      From cppreference.com
      <cpp‎ |io‎ |ios base
       
       
       
       
      typedef/* implementation defined */ openmode;
      staticconstexpr openmode app      =/* implementation defined */;

      staticconstexpr openmode binary    =/* implementation defined */;
      staticconstexpr openmode in        =/* implementation defined */;
      staticconstexpr openmode out      =/* implementation defined */;
      staticconstexpr openmode trunc    =/* implementation defined */;

      staticconstexpr openmode ate      =/* implementation defined */;
      staticconstexpr openmode noreplace=/* implementation defined */;
      (since C++23)

      Specifies available file open flags. It is aBitmaskType, the following constants are defined:

      Constant Explanation
      app seek to the end of stream before each write
      binary open inbinary 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(){constchar* fname="unique_name.txt"; // write to a temporary stream objectstd::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 ofstd::basic_filebuf<CharT,Traits>)[edit]
      constructs abasic_stringbuf object
      (public member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/ios_base/openmode&oldid=155274"

      [8]ページ先頭

      ©2009-2025 Movatter.jp