std::ostream_iterator - cppreference.com
From cppreference.com
| Defined in header |
||
|
|
(until C++17) | |
|
|
(since C++17) | |
std::ostream_iterator is a single-pass LegacyOutputIterator that writes successive objects of type T into the std::basic_ostream object for which it was constructed, using operator<<. Optional delimiter string is written to the output stream after every write operation. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the std::ostream_iterator is a no-op.
In a typical implementation, the only data members of std::ostream_iterator are a pointer to the associated std::basic_ostream and a pointer to the first character in the delimiter string.
When writing characters, std::ostreambuf_iterator is more efficient, since it avoids the overhead of constructing and destructing the sentry object once per character.
Member types
| Member type | Definition | ||||
iterator_category
|
std::output_iterator_tag
| ||||
value_type
|
void
| ||||
difference_type
|
| ||||
pointer
|
void
| ||||
reference
|
void
| ||||
char_type
|
CharT
| ||||
traits_type
|
Traits
| ||||
ostream_type
|
std::basic_ostream<CharT, Traits>
|
|
Member types |
(until C++17) |
Member functions
Example
#include <iostream> #include <iterator> #include <numeric> #include <sstream> int main() { std::istringstream str("0.11 0.22 0.33 0.44"); std::partial_sum(std::istream_iterator<double>(str), std::istream_iterator<double>(), std::ostream_iterator<double>(std::cout, ", ")); std::cout << '\n'; }
Output: