std:: ostream_iterator
|
헤더 파일에 정의됨
<iterator>
|
||
|
template
<
class
T,
class
CharT
=
char
,
|
(C++17 이전) | |
|
template
<
class
T,
class
CharT
=
char
,
|
(C++17 이후) | |
std::ostream_iterator
는 연속적인
T
타입 객체들을 생성 시 주어진
std::basic_ostream
객체에
operator<<
를 사용하여 기록하는 단일 패스
LegacyOutputIterator
입니다. 선택적 구분자 문자열은 모든 기록 작업 후 출력 스트림에 기록됩니다. 기록 작업은 반복자(역참조 여부와 관계없이)에 할당이 이루어질 때 수행됩니다.
std::ostream_iterator
를 증가시키는 것은 아무 작업도 수행하지 않습니다.
일반적인 구현에서
std::ostream_iterator
의 유일한 데이터 멤버는 연관된
std::basic_ostream
에 대한 포인터와 구분자 문자열의 첫 번째 문자에 대한 포인터입니다.
문자를 기록할 때, std::ostreambuf_iterator 가 더 효율적입니다. 왜냐하면 문자당 한 번씩 센트리 객체를 생성하고 파괴하는 오버헤드를 피할 수 있기 때문입니다.
목차 |
멤버 타입
| 멤버 타입 | 정의 | ||||
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)
|
연속적인 요소들을 출력 스트림에 기록하고 인접한 요소들을 구분자로 분리하는 출력 반복자
(클래스 템플릿) |