Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ostreambuf_iterator

      From cppreference.com
      <cpp‎ |iterator
       
       
      Iterator library
      Iterator concepts
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
       
      Defined in header<iterator>
      template<class CharT,class Traits=std::char_traits<CharT>>

      class ostreambuf_iterator

         :publicstd::iterator<std::output_iterator_tag,void,void,void,void>
      (until C++17)
      template<class CharT,class Traits=std::char_traits<CharT>>
      class ostreambuf_iterator;
      (since C++17)

      std::ostreambuf_iterator is a single-passLegacyOutputIterator that writes successive characters into thestd::basic_streambuf object for which it was constructed. The actual write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing thestd::ostreambuf_iterator is a no-op.

      In a typical implementation, the only data members ofstd::ostreambuf_iterator are a pointer to the associatedstd::basic_streambuf and a boolean flag indicating if the end of file condition has been reached.

      Contents

      [edit]Member types

      Member type Definition
      iterator_categorystd::output_iterator_tag
      value_typevoid
      difference_type

      void

      (until C++20)

      std::ptrdiff_t

      (since C++20)
      pointervoid
      referencevoid
      char_typeCharT
      traits_typeTraits
      streambuf_typestd::basic_streambuf<CharT, Traits>
      ostream_typestd::basic_ostream<CharT, Traits>

      Member typesiterator_category,value_type,difference_type,pointer andreference are required to be obtained by inheriting fromstd::iterator<std::output_iterator_tag,void,void,void,void>.

      (until C++17)

      [edit]Member functions

      constructs a newostreambuf_iterator
      (public member function)[edit]
      (destructor)
      (implicitly declared)
      destructs anostreambuf_iterator
      (public member function)[edit]
      writes a character to the associated output sequence
      (public member function)[edit]
      no-op
      (public member function)[edit]
      no-op
      (public member function)[edit]
      tests if output failed
      (public member function)[edit]

      [edit]Example

      Run this code
      #include <algorithm>#include <iostream>#include <iterator>#include <string> int main(){std::string s="This is an example\n";std::copy(s.begin(), s.end(), std::ostreambuf_iterator<char>(std::cout));}

      Output:

      This is an example

      [edit]See also

      input iterator that reads fromstd::basic_streambuf
      (class template)[edit]
      output iterator that writes tostd::basic_ostream
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/ostreambuf_iterator&oldid=160128"

      [8]ページ先頭

      ©2009-2025 Movatter.jp