std::ostreambuf_iterator<CharT,Traits>::ostreambuf_iterator

From cppreference.com
 
 
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
Utilities
(C++20)
Iterator adaptors
Stream iterators
Iterator customization points
Iterator operations
(C++11)
(C++11)
Range access
(C++11)(C++14)
(C++11)(C++14)
(C++17)(C++20)
(C++14)(C++14)
(C++14)(C++14)
(C++17)
(C++17)
 
 
(1)
ostreambuf_iterator( streambuf_type* buffer ) throw();
(until C++11)
ostreambuf_iterator( streambuf_type* buffer ) noexcept;
(since C++11)
(2)
ostreambuf_iterator( ostream_type& stream ) throw();
(until C++11)
ostreambuf_iterator( ostream_type& stream ) noexcept;
(since C++11)
1) Constructs the iterator with the private streambuf_type* member set to buffer and the failed() flag set to false. The behavior is undefined if buffer is a null pointer.
2) Same as ostreambuf_iterator(stream.rdbuf()).

Parameters

stream - the output stream whose rdbuf() will be accessed by this iterator
buffer - the output stream buffer to be accessed by this iterator

Example

#include <iostream>
#include <fstream>
#include <iterator>
int main()
{
    std::basic_filebuf<char> f;
    f.open("test.txt", std::ios::out);
 
    std::ostreambuf_iterator<char> out1(&f);
 
    std::ostreambuf_iterator<wchar_t> out2(std::wcout);
 
    *out1 = 'a';
    *out2 = L'a';
}

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
P2325R3 C++20 default constructor was provided as C++20 iterators
must be default_initializable
removed along with the requirement