Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_ospanstream<CharT,Traits>::basic_ospanstream

      From cppreference.com
      <cpp‎ |io‎ |basic ospanstream

      [edit template]
       
       
       
       
      explicit basic_ospanstream(std::span<CharT> s,std::ios_base::openmode mode=
                                     std::ios_base::out);
      (1)(since C++23)
      basic_ospanstream( basic_ospanstream&& rhs);
      (2)(since C++23)
      basic_ospanstream(const basic_ospanstream&)= delete;
      (3)(since C++23)

      Constructs a newbasic_ospanstream.

      1) Uses the storage referenced bys as initial underlying buffer of the wrappedstd::basic_spanbuf device. The wrappedstd::basic_spanbuf object is constructed asbasic_spanbuf<Char, Traits>(s, mode|std::ios_base::out).
      2) Move constructor. Move constructs thestd::basic_ostream base subobject and the wrappedstd::basic_spanbuf from those ofrhs, and then callsset_rdbuf with the address of the wrappedstd::basic_spanbuf in*this to install it.
      3) Copy constructor is deleted.basic_ospanstream is not copyable.

      Contents

      [edit]Parameters

      s -std::span referencing the storage to be use as initial underlying buffer of stream
      mode - specifies stream open mode. Following constants and bit-wise OR between them may be used:
      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
      other - anotherbasic_ospanstream to be moved from

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Example

      Run this code
      #include <array>#include <iostream>#include <spanstream> int main(){std::array<char,10> buffer;std::ospanstream os(buffer);    os<<"i="<<1<<" j="<<2<<'\n'<<std::ends; std::cout<< buffer.data();}

      Output:

      i=1 j=2

      [edit]See also

      constructs abasic_spanbuf object
      (public member function ofstd::basic_spanbuf<CharT,Traits>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_ospanstream/basic_ospanstream&oldid=130842"

      [8]ページ先頭

      ©2009-2026 Movatter.jp