Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_streambuf

      From cppreference.com
      <cpp‎ |io
       
       
       
      std::basic_streambuf
       
      Defined in header<streambuf>
      template<

         class CharT,
         class Traits=std::char_traits<CharT>

      >class basic_streambuf;

      The classbasic_streambuf controls input and output to a character sequence. It includes and provides access to

      1. Thecontrolled character sequence, also called thebuffer, which may containinput sequence (also calledget area) for buffering the input operations and/oroutput sequence (also calledput area) for buffering the output operations.
      2. Theassociated character sequence, also calledsource (for input) orsink (for output). This may be an entity that is accessed through OS API (file, TCP socket, serial port, other character device), or it may be an object (std::vector,array,string literal), that can be interpreted as a character source or sink.

      The I/O stream objectsstd::basic_istream andstd::basic_ostream, as well as all objects derived from them (std::ofstream,std::stringstream, etc), are implemented entirely in terms ofstd::basic_streambuf.

      The controlled character sequence is an array ofCharT which, at all times, represents a subsequence, or a "window" into the associated character sequence. Its state is described by three pointers:

      1. Thebeginning pointer, always points at the lowest element of the buffer.
      2. Thenext pointer, points at the element that is the next candidate for reading or writing.
      3. Theend pointer, points one past the end of the buffer.

      Abasic_streambuf object may support input (in which case the buffer described by the beginning, next, and end pointers is calledget area), output (put area), or input and output simultaneously. In latter case, six pointers are tracked, which may all point to elements of the same character array or two individual arrays.

      If the next pointer is less than the end pointer in the put area, awrite position is available. The next pointer can be dereferenced and assigned to.

      If the next pointer is less than the end pointer in the get area, aread position is available. The next pointer can be dereferenced and read from.

      If the next pointer is greater than the beginning pointer in a get area, aputback position is available, and the next pointer may be decremented, dereferenced, and assigned to, in order to put a character back into the get area.

      The character representation and encoding in the controlled sequence may be different from the character representations in the associated sequence, in which case astd::codecvt locale facet is typically used to perform the conversion. Common examples are UTF-8 (or other multibyte) files accessed throughstd::wfstream objects: the controlled sequence consists ofwchar_t characters, but the associated sequence consists of bytes.

      Typical implementation of thestd::basic_streambuf base class holds only the sixCharT* pointers and a copy ofstd::locale as data members. In addition, implementations may keep cached copies of locale facets, which are invalidated wheneverimbue() is called. The concrete buffers such asstd::basic_filebuf orstd::basic_stringbuf are derived fromstd::basic_streambuf.

      std-streambuf.svg

      Several typedefs for common character types are provided:

      Defined in header<streambuf>
      Type Definition
      std::streambufstd::basic_streambuf<char>
      std::wstreambufstd::basic_streambuf<wchar_t>

      Contents

      [edit]Member types

      Member type Definition
      char_typeCharT[edit]
      traits_typeTraits; the program is ill-formed ifTraits::char_type is notCharT.[edit]
      int_typeTraits::int_type[edit]
      pos_typeTraits::pos_type[edit]
      off_typeTraits::off_type[edit]

      [edit]Member functions

      [virtual]
      destructs thebasic_streambuf object
      (virtual public member function)[edit]
      Locales
      changes the associated locale and invokesimbue()
      (public member function)[edit]
      obtains a copy of the associated locale
      (public member function)[edit]
      Positioning
      invokessetbuf()
      (public member function)[edit]
      invokesseekoff()
      (public member function)[edit]
      invokesseekpos()
      (public member function)[edit]
      invokessync()
      (public member function)[edit]
      Get area
      obtains the number of characters immediately available in the get area
      (public member function)[edit]
      advances the input sequence, then reads one character without advancing again
      (public member function)[edit]
      (removed in C++17)
      reads one character from the input sequence and advances the sequence
      (public member function)[edit]
      reads one character from the input sequence without advancing the sequence
      (public member function)[edit]
      invokesxsgetn()
      (public member function)[edit]
      Put area
      writes one character to the put area and advances the next pointer
      (public member function)[edit]
      invokesxsputn()
      (public member function)[edit]
      Putback
      puts one character back in the input sequence
      (public member function)[edit]
      moves the next pointer in the input sequence back by one
      (public member function)[edit]

      Protected member functions

      constructs abasic_streambuf object
      (protected member function)[edit]
      (C++11)
      replaces abasic_streambuf object
      (protected member function)[edit]
      (C++11)
      swaps twobasic_streambuf objects
      (protected member function)[edit]
      Locales
      [virtual]
      reacts to a change of the associated locale
      (virtual protected member function)[edit]
      Positioning
      [virtual]
      replaces the buffer with user-defined array, if permitted
      (virtual protected member function)[edit]
      [virtual]
      repositions the next pointer in the input sequence, output sequence, or both, using relative addressing
      (virtual protected member function)[edit]
      [virtual]
      repositions the next pointer in the input sequence, output sequence, or both using absolute addressing
      (virtual protected member function)[edit]
      [virtual]
      synchronizes the buffers with the associated character sequence
      (virtual protected member function)[edit]
      Get area
      [virtual]
      obtains the number of characters available for input in the associated input sequence, if known
      (virtual protected member function)[edit]
      [virtual]
      reads characters from the associated input sequence to the get area
      (virtual protected member function)[edit]
      [virtual]
      reads characters from the associated input sequence to the get area and advances the next pointer
      (virtual protected member function)[edit]
      [virtual]
      reads multiple characters from the input sequence
      (virtual protected member function)[edit]
      returns a pointer to the beginning, current character and the end of the get area
      (protected member function)[edit]
      advances the next pointer in the input sequence
      (protected member function)[edit]
      repositions the beginning, next, and end pointers of the input sequence
      (protected member function)[edit]
      Put area
      [virtual]
      writes multiple characters to the output sequence
      (virtual protected member function)[edit]
      [virtual]
      writes characters to the associated output sequence from the put area
      (virtual protected member function)[edit]
      returns a pointer to the beginning, current character and the end of the put area
      (protected member function)[edit]
      advances the next pointer of the output sequence
      (protected member function)[edit]
      repositions the beginning, next, and end pointers of the output sequence
      (protected member function)[edit]
      Putback
      [virtual]
      puts a character back into the input sequence, possibly modifying the input sequence
      (virtual protected member function)[edit]

      [edit]See also

      object type, capable of holding all information needed to control a C I/O stream
      (typedef)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_streambuf&oldid=165210"

      [8]ページ先頭

      ©2009-2025 Movatter.jp