Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::ostream_joiner

      From cppreference.com
      <cpp‎ |experimental
       
       
       
       
       
      Defined in header<experimental/iterator>
      template<

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

      class ostream_joiner;
      (library fundamentals TS v2)

      std::experimental::ostream_joiner is a single-passLegacyOutputIterator that writes successive objects into thestd::basic_ostream object for which it was constructed, usingoperator<<, separated by a delimiter. The delimiter is written to the output stream between every two objects that are written. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing theostream_joiner is a no-op.

      In a typical implementation, the only data members ofostream_joiner are a pointer to the associatedstd::basic_ostream, the delimiter, and abool member that indicates whether the next write is for the first element in the sequence.

      Compared tostd::ostream_iterator,ostream_joiner prints the delimiter sequence one fewer time, and is not templated on the type of the object to be printed.

      Contents

      [edit]Member types

      Member type Definition
      char_typeCharT
      traits_typeTraits
      ostream_typestd::basic_ostream<CharT, Traits>
      value_typevoid
      difference_typevoid
      pointervoid
      referencevoid
      iterator_categorystd::output_iterator_tag

      [edit]Member functions

      constructs a newostream_joiner
      (public member function)[edit]
      (destructor)
      (implicitly declared)
      destructs anostream_joiner
      (public member function)[edit]
      writes an object to the associated output sequence
      (public member function)[edit]
      no-op
      (public member function)[edit]
      no-op
      (public member function)[edit]

      [edit]Non-member functions

      creates anostream_joiner object, deducing the template's type arguments from the function arguments
      (function template)[edit]

      [edit]Example

      Run this code
      #include <algorithm>#include <experimental/iterator>#include <iostream>#include <iterator> int main(){int i[]={1,2,3,4,5};std::copy(std::begin(i),std::end(i),std::experimental::make_ostream_joiner(std::cout,", "));}

      Output:

      1, 2, 3, 4, 5

      [edit]See also

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

      [8]ページ先頭

      ©2009-2025 Movatter.jp