ostreambuf_iterator 클래스

클래스 템플릿 ostreambuf_iterator 추출 연산>>자를 사용하여 출력 스트림에 연속 문자 요소를 쓰는 출력 반복기 개체를 설명합니다. ostreambuf_iterator는 출력 스트림에 삽입하는 개체 형식이 제네릭 형식이 아닌 문자이라는 점에서 ostream_iterator 클래스와 다릅니다.

구문

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

매개 변수

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

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

설명

ostreambuf_iterator 클래스는 출력 반복기에 대한 요구 사항을 충족해야 합니다. 알고리즘은 ostreambuf_iterator를 사용하여 출력 스트림에 직접 쓸 수 있습니다. 이 클래스에서는 문자의 형태로 원시(서식이 지정되지 않은) I/O 스트림 액세스를 허용하는 낮은 수준의 스트림 반복기를 제공하고 버퍼링을 우회할 수 있으며 높은 수준의 스트림 반복기에서 나타나는 문자 변환이 없습니다.

생성자

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

Typedef

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

멤버 함수

멤버 함수 설명
failed 출력 스트림 버퍼에 대한 삽입 실패를 테스트합니다.

연산자

연산자 설명
operator* 출력 반복기 식 * i = x을 구현하는 데 사용된 역참조 연산자.
operator++ 연산이 호출되기 전에 주소 지정한 동일한 개체에 ostreambuf_iterator를 반환한 비함수 증분 연산자.
operator= 연산자가 연결된 스트림 버퍼에 문자를 삽입합니다.

요구 사항

헤더:<반복기>

네임스페이스: std

ostreambuf_iterator::char_type

ostreambuf_iterator의 문자 형식을 허용하는 형식입니다.

typedef CharType char_type;

설명

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

예시

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

int main( )
{
   using namespace std;

   typedef ostreambuf_iterator<char>::char_type CHT1;
   typedef ostreambuf_iterator<char>::traits_type CHTR1;

   // ostreambuf_iterator for stream cout
   // with new line delimiter:
    ostreambuf_iterator< CHT1, CHTR1> charOutBuf ( cout );

   // Standard iterator interface for writing
   // elements to the output streambuf:
   cout << "The characters written to the output stream\n"
        << " by charOutBuf are: ";
*charOutBuf = 'O';
   charOutBuf++;
*charOutBuf = 'U';
   charOutBuf++;
*charOutBuf = 'T';
   charOutBuf++;
   cout << "." << endl;
}
/* Output:
The characters written to the output stream
by charOutBuf are: OUT.
*/

ostreambuf_iterator::failed

출력 스트림 버퍼에 대한 삽입 실패를 테스트합니다.

bool failed() const throw();

Return Value

true 출력 스트림 버퍼에 이전에 삽입하지 못한 경우 그렇지 않으면 false.

설명

멤버 함수는 이전에 멤버operator=를 사용할 때 subf_-sputc>에 대한 호출이 eof를 반환하는 경우를 반환 true 합니다.

예시

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

int main( )
{
   using namespace std;

   // ostreambuf_iterator for stream cout
   ostreambuf_iterator<char> charOut ( cout );

*charOut = 'a';
   charOut ++;
*charOut  = 'b';
   charOut ++;
*charOut = 'c';
   cout << " are characters output individually." << endl;

   bool b1 = charOut.failed ( );
   if (b1)
       cout << "At least one insertion failed." << endl;
   else
       cout << "No insertions failed." << endl;
}
/* Output:
abc are characters output individually.
No insertions failed.
*/

ostreambuf_iterator::operator*

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

ostreambuf_iterator<CharType, Traits>& operator*();

Return Value

ostreambuf 반복기 개체입니다.

설명

이 연산자는 출력 반복기 식 * i = x에서만 함수를 실행하여 스트림 버퍼에 문자를 출력합니다. ostreambuf 반복기에 적용되면 반복기가 반환됩니다. *반복기가 반복기를 반환합니다.

예시

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

int main( )
{
   using namespace std;

   // ostreambuf_iterator for stream cout
   // with new line delimiter
   ostreambuf_iterator<char> charOutBuf ( cout );

   // Standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
*charOutBuf = 'O';
   charOutBuf++;   // no effect on iterator position
*charOutBuf = 'U';
*charOutBuf = 'T';
}
/* Output:
Elements written to output stream:
OUT
*/

ostreambuf_iterator::operator++

연산이 호출되기 전에 주소 지정한 동일한 문자에 대한 ostream 반복기를 반환하는 작동하지 않는 증분 연산자입니다.

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

Return Value

원래 주소가 지정된 문자 또는 CharType, Traits>로 변환할 수 있는 구현 정의 개체에 ostreambuf_iterator<대한 참조입니다.

설명

연산자는 출력 반복기 식 * i = x를 구현하는 데 사용됩니다.

예시

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

int main( )
{
   using namespace std;

   // ostreambuf_iterator for stream cout
   // with new line delimiter
   ostreambuf_iterator<char> charOutBuf ( cout );

   // Standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
*charOutBuf = 'O';
   charOutBuf++;      // No effect on iterator position
*charOutBuf = 'U';
*charOutBuf = 'T';
}
/* Output:
Elements written to output stream:
OUT
*/

ostreambuf_iterator::operator=

연산자가 연결된 스트림 버퍼에 문자를 삽입합니다.

ostreambuf_iterator<CharType, Traits>& operator=(CharType _Char);

매개 변수

_Char
스트림 버퍼에 삽입할 문자입니다.

Return Value

스트림 버퍼에 삽입되는 문자에 대한 참조입니다.

설명

출력 반복기 식을 구현하는 데 사용되는 대입 연산자 * 출력 스트림에 쓰기 위한 i = x입니다.

예시

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

int main( )
{
   using namespace std;

   // ostreambuf_iterator for stream cout
   // with new line delimiter
   ostreambuf_iterator<char> charOutBuf ( cout );

   // Standard iterator interface for writing
   // elements to the output stream
   cout << "Elements written to output stream:" << endl;
*charOutBuf = 'O';
   charOutBuf++;      // No effect on iterator position
*charOutBuf = 'U';
*charOutBuf = 'T';
}
/* Output:
Elements written to output stream:
OUT
*/

ostreambuf_iterator::ostreambuf_iterator

출력 스트림으로 문자를 쓰도록 초기화된 ostreambuf_iterator를 구성합니다.

ostreambuf_iterator(streambuf_type* strbuf) throw();
ostreambuf_iterator(ostream_type& Ostr) throw();

매개 변수

strbuf
출력 스트림 버퍼 포인터를 초기화하는 데 사용되는 출력 streambuf 개체입니다.

Ostr
출력 스트림 버퍼 포인터를 초기화하는 데 사용되는 출력 stream 개체입니다.

설명

첫 번째 생성자는 strbuf를 사용하여 출력 스트림 버퍼 포인터를 초기화합니다.

두 번째 생성자는 Ostr로 출력 스트림 버퍼 포인터를 초기화합니다. rdbuf. 저장된 포인터는 null 포인터가 아니어야 합니다.

예시

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

int main( )
{
   using namespace std;

   // ostreambuf_iterator for stream cout
   ostreambuf_iterator<char> charOut ( cout );

*charOut = 'O';
   charOut ++;
*charOut  = 'U';
   charOut ++;
*charOut = 'T';
   cout << " are characters output individually." << endl;

   ostreambuf_iterator<char> strOut ( cout );
   string str = "These characters are being written to the output stream.\n ";
   copy ( str.begin ( ), str. end ( ), strOut );
}
/* Output:
OUT are characters output individually.
These characters are being written to the output stream.
*/

ostreambuf_iterator::ostream_type

ostream_iterator의 스트림 형식을 허용하는 형식입니다.

typedef basicOstream<CharType, Traits> ostream_type;

설명

이 형식은 basicOstream<CharType, Traits>와 동일한 의미입니다.

예시

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

ostreambuf_iterator::streambuf_type

ostreambuf_iterator의 스트림 형식을 허용하는 형식입니다.

typedef basic_streambuf<CharType, Traits> streambuf_type;

설명

이 형식은 문자 형식에 특수basic_streambuf<화될 때 되는 I/O 버퍼의 스트림 클래스인 CharType, Traitsstreambuf>의 동의어입니다.char

예시

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

ostreambuf_iterator::traits_type

ostream_iterator의 특성 형식을 허용하는 형식입니다.

typedef Traits traits_type;

설명

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

예시

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

int main( )
{
   using namespace std;

   typedef ostreambuf_iterator<char>::char_type CHT1;
   typedef ostreambuf_iterator<char>::traits_type CHTR1;

   // ostreambuf_iterator for stream cout
   // with new line delimiter:
    ostreambuf_iterator< CHT1, CHTR1> charOutBuf ( cout );

   // Standard iterator interface for writing
   // elements to the output streambuf:
   cout << "The characters written to the output stream\n"
        << " by charOutBuf are: ";
*charOutBuf = 'O';
   charOutBuf++;
*charOutBuf = 'U';
   charOutBuf++;
*charOutBuf = 'T';
   charOutBuf++;
   cout << "." << endl;
}
/* Output:
The characters written to the output stream
by charOutBuf are: OUT.
*/

참고 항목

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