Namespaces
Variants

std::ostream_iterator<T,CharT,Traits>:: operator=

From cppreference.net
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
(C++20)
Iterator adaptors
Range access
(C++11) (C++14)
(C++14) (C++14)
(C++11) (C++14)
(C++14) (C++14)
(C++17) (C++20)
(C++17)
(C++17)
ostream_iterator & operator = ( const ostream_iterator & ) ;
(1)
ostream_iterator & operator = ( const T & value ) ;
(2)
1) 복사 할당 연산자. other 의 내용을 할당합니다.
2) 연결된 스트림에 value 를 삽입한 다음, 생성 시점에 지정된 구분자가 있는 경우 구분자를 삽입합니다.

만약 out_stream 이 연결된 std::basic_ostream 을 가리키는 포인터이고 delim 이 이 객체의 생성 시 지정된 구분자라면, 효과는 다음과 동일합니다

* out_stream << value ;
if ( delim ! = 0 )
* out_stream << delim ;
return * this ;

목차

매개변수

value - 삽입할 객체

반환값

* this

참고 사항

T 는 사용자 정의 operator<< 를 가진 모든 클래스가 될 수 있습니다.

C++20 이전에는 복사 할당 연산자의 존재가 사용 중단된 암시적 생성 에 의존했습니다.

예제

#include <iostream>
#include <iterator>
int main()
{
    std::ostream_iterator<int> i1(std::cout, ", ");
    *i1++ = 1; // 일반적인 형태, 표준 알고리즘에서 사용됨
    *++i1 = 2;
    i1 = 3; // *나 ++ 연산자가 필요하지 않음
    std::ostream_iterator<double> i2(std::cout);
    i2 = 3.14;
    std::cout << '\n';
}

출력:

1, 2, 3, 3.14