std::ostream_iterator
| 헤더에 정의됨 <iterator>
|
||
template< class T,
class CharT = char,
class Traits = std::char_traits<CharT> >
class ostream_iterator
: public std::iterator<std::output_iterator_tag, void, void, void, void>
|
(C++17까지) | |
template< class T,
class CharT = char,
class Traits = std::char_traits<CharT> >
class ostream_iterator;
|
(C++17부터) | |
std::ostream_iterator는 단일 패스 LegacyOutputIterator로, 타입 T의 연속적인 객체를 std::basic_ostream 객체에 (생성될 때 지정된) operator<<를 사용하여 씁니다. 선택적 구분자 문자열은 각 쓰기 연산 후에 출력 스트림에 기록됩니다. 쓰기 연산은 반복자(역참조 여부와 관계없이)에 대입될 때 수행됩니다. std::ostream_iterator를 증가시키는 것은 아무 작업도 하지 않습니다.
일반적인 구현에서, std::ostream_iterator의 유일한 데이터 멤버는 연관된 std::basic_ostream에 대한 포인터와 구분자 문자열의 첫 번째 문자에 대한 포인터입니다.
문자를 쓸 때, std::ostreambuf_iterator가 더 효율적입니다. 문자당 sentry 객체를 생성 및 소멸하는 오버헤드를 피하기 때문입니다.
멤버 타입
| 멤버 타입 | 정의 | ||||
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 > |
|
멤버 타입
|
(C++17 이전) |
멤버 함수
|
새로운 ostream_iterator를 생성합니다
(public member function) |
|
ostream_iterator
를 소멸시킵니다
(public member function) |
|
|
객체를 연관된 출력 시퀀스에 기록합니다
(public member function) |
|
|
아무 작업도 수행하지 않음
(public member function) |
|
|
아무 작업도 수행하지 않음
(public member function) |
예제
#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'; }
출력:
0.11, 0.33, 0.66, 1.1,
참고 항목
|
std::basic_streambuf
에 쓰기를 수행하는 출력 반복자
(클래스 템플릿) |
|
|
std::basic_istream
에서 읽기를 수행하는 입력 반복자
(클래스 템플릿) |
|
|
(library fundamentals TS v2)
|
연속적인 요소들을 출력 스트림에 기록하고 인접한 요소들을 구분자로 분리하는 출력 반복자
(클래스 템플릿) |