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

From cppreference.com
 
 
Iterator library
Iterator concepts
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)

Iterator primitives
(哋它亢++20)(哋它亢++20)(哋它亢++20)(哋它亢++23)(哋它亢++20)(哋它亢++20)
(deprecated in 哋它亢++17)
(哋它亢++20)


Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)  
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Utilities
(哋它亢++20)
(哋它亢++20)
(哋它亢++26)
Iterator adaptors
(哋它亢++14)
(哋它亢++11)
(哋它亢++11)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)
(哋它亢++23)

Iterator operations
(哋它亢++11)  
(哋它亢++11)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
Range access
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++11)(哋它亢++14)
(哋它亢++14)(哋它亢++14)  
(哋它亢++17)(哋它亢++20)
(哋它亢++17)
(哋它亢++17)
 
 
(1)
ostreambuf_iterator( streambuf_type* buffer ) throw();
(until 哋它亢++11)
ostreambuf_iterator( streambuf_type* buffer ) noexcept;
(since 哋它亢++11)
(2)
ostreambuf_iterator( ostream_type& stream ) throw();
(until 哋它亢++11)
ostreambuf_iterator( ostream_type& stream ) noexcept;
(since 哋它亢++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 <fstream>
#include <iostream>
#include <iterator>
 
int main()
{
    const char* file = "test.txt";
    {
        std::basic_filebuf<char> f;
        f.open(file, std::ios::out);
        std::ostreambuf_iterator<char> out1(&f);
        *out1 = 'a'; // writes to file via iterator
    }
 
    // read back from the file
    char a;
    std::cout << ((std::ifstream{file} >> a), a) << std::endl;
 
    std::ostreambuf_iterator<wchar_t> out2{std::wcout};
    *out2 = L'b';
}

Output:

a
b

Defect reports

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

DR Applied to Behavior as published Correct behavior
LWG 112 哋它亢++98 the requirement "the argument cannot
be null" was applied to overload (2)
applies to overload
(1) instead
P2325R3 哋它亢++20 default constructor was provided as 哋它亢++20
iterators must be default_initializable
removed along with
the requirement