ostream_iterator 클래스

클래스 템플릿 ostream_iterator 추출을 사용하여 출력 스트림에 연속 요소를 쓰는 출력 반복기 개체를 설명합니다 operator <<.

구문

template <class Type class CharType = char class Traits = char_traits <CharType>>
class ostream_iterator

매개 변수

Type
출력 스트림에 삽입될 개체의 형식입니다.

CharType
ostream_iterator의 문자 형식을 나타내는 형식입니다. 이 인수는 선택 사항이며 기본값은 char입니다.

특성
ostream_iterator의 문자 형식을 나타내는 형식입니다. 이 인수는 선택 사항이며 기본값은 CharType>입니다char_traits<.

ostream_iterator 클래스는 출력 반복기에 대한 요구 사항을 충족해야 합니다. 알고리즘은 ostream_iterator를 사용하여 출력 스트림에 직접 쓸 수 있습니다.

생성자

생성자 Description
ostream_iterator 출력 스트림으로 쓰도록 초기화 및 구분된 ostream_iterator를 구성합니다.

Typedef

형식 이름 설명
char_type ostream_iterator의 문자 형식을 허용하는 형식입니다.
ostream_type ostream_iterator의 스트림 형식을 허용하는 형식입니다.
traits_type ostream_iterator의 특성 형식을 허용하는 형식입니다.

연산자

연산자 설명
operator* 출력 반복기 식 * i = x을 구현하는 데 사용된 역참조 연산자.
operator++ 연산이 호출되기 전에 주소 지정한 동일한 개체에 ostream_iterator를 반환한 비함수 증분 연산자.
operator= 출력 스트림을 작성하기 위해 출력 반복기 식 * i = x을 구현하는 데 사용된 할당 연산자.

요구 사항

헤더:<반복기>

네임스페이스: std

ostream_iterator::char_type

반복기의 문자 형식을 제공하는 형식입니다.

typedef CharType char_type;

설명

이 형식은 템플릿 매개 변수 CharType의 동의어입니다.

예시

// ostream_iterator_char_type.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   typedef ostream_iterator<int>::char_type CHT1;
   typedef ostream_iterator<int>::traits_type CHTR1;

   // ostream_iterator for stream cout
   // with new line delimiter:
    ostream_iterator<int, CHT1, CHTR1> intOut ( cout , "\n" );

   // Standard iterator interface for writing
   // elements to the output stream:
   cout << "The integers written to the output stream\n"
        << "by intOut are:" << endl;
*intOut = 10;
*intOut = 20;
*intOut = 30;
}
/* Output:
The integers written to the output stream
by intOut are:
10
20
30
*/

ostream_iterator::operator*

출력 반복기 식 * ii = x를 구현하는 데 사용되는 역참조 연산자입니다.

ostream_iterator<Type, CharType, Traits>& operator*();

Return Value

ostream_iterator에 대한 참조입니다.

설명

충족해야 하는 ostream_iterator 출력 반복기에 대한 요구 사항은 식 * ii = 만 유효하지 않으며 자체 또는 operator= 자체에 대해 operator 아무 말도 하지 않아야 합니다. 이 구현의 멤버 연산자는 .*this

예시

// ostream_iterator_op_deref.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // ostream_iterator for stream cout
   // with new line delimiter
   ostream_iterator<int> intOut ( cout , "\n" );

   // Standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
*intOut = 10;
   intOut++;      // No effect on iterator position
*intOut = 20;
*intOut = 30;
}
/* Output:
Elements written to output stream:
10
20
30
*/

ostream_iterator::operator++

연산이 호출되기 전에 주소 지정한 동일한 개체에 ostream_iterator를 반환한 비함수 증분 연산자.

ostream_iterator<Type, CharType, Traits>& operator++();
ostream_iterator<Type, CharType, Traits> operator++(int);

Return Value

ostream_iterator에 대한 참조입니다.

설명

이러한 멤버 연산자는 모두 반환됩니다 *this.

예시

// ostream_iterator_op_incr.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // ostream_iterator for stream cout
   // with new line delimiter
   ostream_iterator<int> intOut ( cout , "\n" );

   // standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
*intOut = 10;
   intOut++;      // No effect on iterator position
*intOut = 20;
*intOut = 30;
}
/* Output:
Elements written to output stream:
10
20
30
*/

ostream_iterator::operator=

출력 스트림을 작성하기 위해 출력 반복기 식 * i = x을 구현하는 데 사용된 할당 연산자입니다.

ostream_iterator<Type, CharType, Traits>& operator=(const Type& val);

매개 변수

val
출력 스트림에 삽입될 Type 형식의 개체 값입니다.

Return Value

연산자는 개체와 연결된 출력 스트림에 val을 삽입한 다음, ostream_iterator 생성자(있는 경우)에 지정된 구분 기호를 삽입한 다음 해당 개체에 대한 참조를 ostream_iterator반환합니다.

설명

ostream_iterator가 충족해야 하는 출력 반복기에 대한 요구 사항은 * ii = t 식만 유효해야 한다는 것과 해당 반복기 자체는 operator 또는 operator=에 대해 어떤 정보도 제공하지 않아야 한다는 것입니다. 이 멤버 연산자는 *this를 반환합니다.

예시

// ostream_iterator_op_assign.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // ostream_iterator for stream cout
   // with new line delimiter
   ostream_iterator<int> intOut ( cout , "\n" );

   // Standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
*intOut = 10;
   intOut++;      // No effect on iterator position
*intOut = 20;
*intOut = 30;
}
/* Output:
Elements written to output stream:
10
20
30
*/

ostream_iterator::ostream_iterator

출력 스트림으로 쓰도록 초기화 및 구분된 ostream_iterator를 구성합니다.

ostream_iterator(
    ostream_type& _Ostr);

ostream_iterator(
    ostream_type& _Ostr,
    const CharType* _Delimiter);

매개 변수

_Ostr
반복할 ostream_iterator::ostream_type 형식의 출력 스트림입니다.

_구분 기호
출력 스트림에서 값 사이에 삽입되는 구분 기호입니다.

설명

첫 번째 생성자는 &_Ostr로 출력 스트림 포인터를 초기화합니다. 구분 기호 문자열 포인터는 빈 문자열을 지정합니다.

두 번째 생성자는 출력 스트림 포인터와 구분 기호 문자열 포인터&_Ostr _Delimiter 초기화합니다.

예시

// ostream_iterator_ostream_iterator.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // ostream_iterator for stream cout
   ostream_iterator<int> intOut ( cout , "\n" );
*intOut = 10;
   intOut++;
*intOut = 20;
   intOut++;

   int i;
   vector<int> vec;
   for ( i = 1 ; i < 7 ; ++i )
   {
      vec.push_back (  i );
   }

   // Write elements to standard output stream
   cout << "Elements output without delimiter: ";
   copy ( vec.begin ( ), vec.end ( ),
          ostream_iterator<int> ( cout ) );
   cout << endl;

   // Write elements with delimiter " : " to output stream
   cout << "Elements output with delimiter: ";
   copy ( vec.begin ( ), vec.end ( ),
          ostream_iterator<int> ( cout, " : " ) );
   cout << endl;
}
/* Output:
10
20
Elements output without delimiter: 123456
Elements output with delimiter: 1 : 2 : 3 : 4 : 5 : 6 :
*/

ostream_iterator::ostream_type

반복기의 스트림 형식을 제공하는 형식입니다.

typedef basic_ostream<CharType, Traits> ostream_type;

설명

이 형식은 쓰기에 사용할 수 있는 개체를 정의하는 iostream 계층 구조의 스트림 클래스인 basic_ostream><CharTypeTraits 동의어입니다.

예시

ostream_type을 선언하고 사용하는 방법의 예제는 ostream_iterator를 참조하세요.

ostream_iterator::traits_type

반복기의 특성 형식을 제공하는 형식입니다.

typedef Traits traits_type;

설명

이 형식은 템플릿 매개 변수 Traits의 동의어입니다.

예시

// ostream_iterator_traits_type.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;

   // The following not OK, but are just the default values:
   typedef ostream_iterator<int>::char_type CHT1;
   typedef ostream_iterator<int>::traits_type CHTR1;

   // ostream_iterator for stream cout
   // with new line delimiter:
    ostream_iterator<int, CHT1, CHTR1> intOut ( cout , "\n" );

   // Standard iterator interface for writing
   // elements to the output stream:
   cout << "The integers written to output stream\n"
        << "by intOut are:" << endl;
*intOut = 1;
*intOut = 10;
*intOut = 100;
}
/* Output:
The integers written to output stream
by intOut are:
1
10
100
*/

참고 항목

<iterator>
C++ 표준 라이브러리의 스레드 보안
C++ 표준 라이브러리 참조