istreambuf_iterator 클래스
클래스 템플릿 istreambuf_iterator 입력 스트림 버퍼에서 문자 요소를 추출하는 입력 반복기 개체를 설명합니다. 이 개체는 저장하는 개체를 통해 액세스하며 CharType, Traits에 basic_streambuf
<대한 형식 포인터를 통해 액세스합니다>.
구문
template <class CharType class Traits = char_traits <CharType>>
class istreambuf_iterator
: public iterator<input_iterator_tag, CharType, typename Traits ::off_type, CharType*, CharType&>
매개 변수
CharType
istreambuf_iterator의 문자 형식을 나타내는 형식입니다.
특성
istreambuf_iterator의 문자 형식을 나타내는 형식입니다. 이 인수는 선택 사항이며 기본값은 CharType>입니다char_traits
<.
설명
istreambuf_iterator 클래스는 입력 반복기에 대한 요구 사항을 충족해야 합니다.
null이 아닌 저장된 포인터를 사용하여 istreambuf_iterator 클래스의 개체를 구성하거나 증가시킨 후 개체는 연결된 입력 스트림에서 CharType 형식의 개체에 대해 효과적인 추출 및 저장을 시도합니다. 그러나 개체가 역참조되거나 복사될 때까지 추출이 지연될 수 있습니다. 추출이 실패할 경우 개체는 저장된 포인터를 null 포인터로 대체하여 시퀀스 끝 표시기를 만듭니다.
생성자
생성자 | Description |
---|---|
istreambuf_iterator | 입력 스트림에서 문자를 읽을 수 있도록 초기화된 istreambuf_iterator 를 만듭니다. |
Typedef
형식 이름 | 설명 |
---|---|
char_type | ostreambuf_iterator 의 문자 형식을 허용하는 형식입니다. |
int_type | istreambuf_iterator 의 정수 형식을 허용하는 형식입니다. |
istream_type | istream_iterator 의 스트림 형식을 허용하는 형식입니다. |
streambuf_type | istreambuf_iterator 의 스트림 형식을 허용하는 형식입니다. |
traits_type | istream_iterator 의 특성 형식을 허용하는 형식입니다. |
멤버 함수
멤버 함수 | 설명 |
---|---|
equal | 두 입력 스트림 버퍼 반복기가 같은지 테스트합니다. |
연산자
연산자 | 설명 |
---|---|
operator* | 역참조 연산자가 스트림의 다음 문자를 반환합니다. |
operator++ | 입력 스트림의 다음 문자를 반환하거나 개체를 증가하기 전에 복사하여 복사본을 반환합니다. |
요구 사항
헤더:<반복기>
네임스페이스: std
istreambuf_iterator::char_type
ostreambuf_iterator
의 문자 형식을 허용하는 형식입니다.
typedef CharType char_type;
설명
이 형식은 템플릿 매개 변수 CharType과 동일한 의미입니다.
예시
// istreambuf_iterator_char_type.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
#include <algorithm>
int main( )
{
using namespace std;
typedef istreambuf_iterator<char>::char_type CHT1;
typedef istreambuf_iterator<char>::traits_type CHTR1;
cout << "(Try the example: 'So many dots to be done'\n"
<< " then an Enter key to insert into the output,\n"
<< " & use a ctrl-Z Enter key combination to exit): ";
// istreambuf_iterator for input stream
istreambuf_iterator< CHT1, CHTR1> charInBuf ( cin );
ostreambuf_iterator<char> charOut ( cout );
// Used in conjunction with replace_copy algorithm
// to insert into output stream and replace spaces
// with dot-separators
replace_copy ( charInBuf , istreambuf_iterator<char>( ),
charOut , ' ' , '.' );
}
istreambuf_iterator::equal
두 입력 스트림 버퍼 반복기가 같은지 테스트합니다.
bool equal(const istreambuf_iterator<CharType, Traits>& right) const;
매개 변수
right
같은지 확인할 반복기입니다.
Return Value
true
둘 다 istreambuf_iterator
스트림의 끝 반복기이거나 스트림 끝 반복기가 아닌 경우, 그렇지 않으면 false
.
설명
범위는 현재 위치 및 스트림 끝 반복기에 의해 istreambuf_iterator
정의되지만, 모든 비엔드 스트림 반복기는 멤버 함수에서 equal
동일하므로 s를 사용하여 istreambuf_iterator
하위 범위를 정의할 수 없습니다. ==
및 !=
연산자는 의미 체계가 동일합니다.
예시
// istreambuf_iterator_equal.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
int main( )
{
using namespace std;
cout << "(Try the example: 'Hello world!'\n"
<< " then an Enter key to insert into the output,\n"
<< " & use a ctrl-Z Enter key combination to exit): ";
istreambuf_iterator<char> charReadIn1 ( cin );
istreambuf_iterator<char> charReadIn2 ( cin );
bool b1 = charReadIn1.equal ( charReadIn2 );
if (b1)
cout << "The iterators are equal." << endl;
else
cout << "The iterators are not equal." << endl;
}
istreambuf_iterator::int_type
istreambuf_iterator
의 정수 형식을 허용하는 형식입니다.
typedef typename traits_type::int_type int_type;
설명
이 형식은 Traits::int_type
의 동의어입니다.
예시
// istreambuf_iterator_int_type.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
int main( )
{
using namespace std;
istreambuf_iterator<char>::int_type inttype1 = 100;
cout << "The inttype1 = " << inttype1 << "." << endl;
}
/* Output:
The inttype1 = 100.
*/
istreambuf_iterator::istream_type
istreambuf_iterator
의 스트림 형식을 허용하는 형식입니다.
typedef basic_istream<CharType, Traits> istream_type;
설명
이 형식은 CharType, Traits의 동의어basic_istream
<입니다>.
예시
istream_type
을 선언하고 사용하는 방법에 대한 예제는 istreambuf_iterator를 참조하세요.
istreambuf_iterator::istreambuf_iterator
입력 스트림에서 문자를 읽을 수 있도록 초기화된 istreambuf_iterator를 생성합니다.
istreambuf_iterator(streambuf_type* strbuf = 0) throw();
istreambuf_iterator(istream_type& _Istr) throw();
매개 변수
strbuf
istreambuf_iterator
를 연결 중인 입력 스트림 버퍼입니다.
_Istr
istreambuf_iterator
를 연결 중인 입력 스트림입니다.
설명
첫 번째 생성자는 strbuf를 사용하여 입력 스트림 버퍼 포인터를 초기화합니다. 두 번째 생성자는 _Istr 사용하여 입력 스트림 버퍼 포인터를 초기화합니다. rdbuf
는 결국 형식 CharType
의 개체를 추출하고 저장하려고 시도합니다.
예시
// istreambuf_iterator_istreambuf_iterator.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <algorithm>
#include <iostream>
int main( )
{
using namespace std;
// Following declarations will not compile:
istreambuf_iterator<char>::istream_type &istrm = cin;
istreambuf_iterator<char>::streambuf_type *strmbf = cin.rdbuf( );
cout << "(Try the example: 'Oh what a world!'\n"
<< " then an Enter key to insert into the output,\n"
<< " & use a ctrl-Z Enter key combination to exit): ";
istreambuf_iterator<char> charReadIn ( cin );
ostreambuf_iterator<char> charOut ( cout );
// Used in conjunction with replace_copy algorithm
// to insert into output stream and replace spaces
// with hyphen-separators
replace_copy ( charReadIn , istreambuf_iterator<char>( ),
charOut , ' ' , '-' );
}
istreambuf_iterator::operator*
역참조 연산자가 스트림의 다음 문자를 반환합니다.
CharType operator*() const;
Return Value
스트림의 다음 문자입니다.
예시
// istreambuf_iterator_operator_deref.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
int main( )
{
using namespace std;
cout << "Type string of characters & enter to output it,\n"
<< " with stream buffer iterators,(try: 'I'll be back.')\n"
<< " repeat as many times as desired,\n"
<< " then keystroke ctrl-Z Enter to exit program: ";
istreambuf_iterator<char> inpos ( cin );
istreambuf_iterator<char> endpos;
ostreambuf_iterator<char> outpos ( cout );
while ( inpos != endpos )
{
*outpos = *inpos; //Put value of outpos equal to inpos
++inpos;
++outpos;
}
}
istreambuf_iterator::operator++
입력 스트림의 다음 문자를 반환하거나 개체를 증가하기 전에 복사하여 복사본을 반환합니다.
istreambuf_iterator<CharType, Traits>& operator++();
istreambuf_iterator<CharType, Traits> operator++(int);
Return Value
istreambuf_iterator
또는 istreambuf_iterator
에 대한 참조입니다.
설명
첫 번째 연산자는 결국 연결된 입력 스트림에서 형식 CharType
의 개체를 추출하고 저장하려고 시도합니다. 두 번째 연산자는 개체의 복사본을 만들고 개체를 증가시킨 다음 복사본을 반환합니다.
예시
// istreambuf_iterator_operator_incr.cpp
// compile with: /EHsc
#include <iterator>
#include <iostream>
int main( )
{
using namespace std;
cout << "Type string of characters & enter to output it,\n"
<< " with stream buffer iterators,(try: 'I'll be back.')\n"
<< " repeat as many times as desired,\n"
<< " then keystroke ctrl-Z Enter to exit program: ";
istreambuf_iterator<char> inpos ( cin );
istreambuf_iterator<char> endpos;
ostreambuf_iterator<char> outpos ( cout );
while ( inpos != endpos )
{
*outpos = *inpos;
++inpos; //Increment istreambuf_iterator
++outpos;
}
}
istreambuf_iterator::streambuf_type
istreambuf_iterator의 스트림 형식을 제공하는 형식입니다.
typedef basic_streambuf<CharType, Traits> streambuf_type;
설명
이 형식은 CharType, Traits의 동의어basic_streambuf
<입니다>.
예시
istreambuf_type
을 선언하고 사용하는 방법에 대한 예제는 istreambuf_iterator를 참조하세요.
istreambuf_iterator::traits_type
istream_iterator
의 특성 형식을 허용하는 형식입니다.
typedef Traits traits_type;
설명
이 형식은 템플릿 매개 변수 Traits와 동일한 의미입니다.
예시
// istreambuf_iterator_traits_type.cpp
// compile with: /EHsc
#include <iterator>
#include <vector>
#include <iostream>
#include <algorithm>
int main( )
{
using namespace std;
typedef istreambuf_iterator<char>::char_type CHT1;
typedef istreambuf_iterator<char>::traits_type CHTR1;
cout << "(Try the example: 'So many dots to be done'\n"
<< " then an Enter key to insert into the output,\n"
<< " & use a ctrl-Z Enter key combination to exit): ";
// istreambuf_iterator for input stream
istreambuf_iterator< CHT1, CHTR1> charInBuf ( cin );
ostreambuf_iterator<char> charOut ( cout );
// Used in conjunction with replace_copy algorithm
// to insert into output stream and replace spaces
// with dot-separators
replace_copy ( charInBuf , istreambuf_iterator<char>( ),
charOut , ' ' , '.' );
}
참고 항목
iterator 구조체
<iterator>
C++ 표준 라이브러리의 스레드 보안
C++ 표준 라이브러리 참조