std::istreambuf_iterator
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <iterator> 中定义
|
||
template< class CharT, class Traits = std::char_traits<CharT> > class istreambuf_iterator : public std::iterator< std::input_iterator_tag, |
||
std::istreambuf_iterator
是读取连续的字符std::basic_streambuf对象,它构建了一个单通输入迭代器。实际的读操作时执行的迭代器是递增的,而不是当它被废弃。该迭代器时建造或完成的第一个间接引用,可以读出的第一个字符。否则,只提领返回最近读的字符的副本.原文:
std::istreambuf_iterator
is a single-pass input iterator that reads successive characters from the std::basic_streambuf object for which it was constructed. The actual read operation is performed when the iterator is incremented, not when it is dereferenced. The first character may be read when the iterator is constructed or when the first dereferencing is done. Otherwise, dereferencing only returns a copy of the most recently read character.被称为“流”迭代器的默认构造
std::istreambuf_iterator
。当一个有效的std::istreambuf_iterator
达到基础流的结束,它变得等于最终的流迭代器。提领或递增的进一步调用未定义的行为.原文:
The default-constructed
std::istreambuf_iterator
is known as the end-of-stream iterator. When a valid std::istreambuf_iterator
reaches the end of the underlying stream, it becomes equal to the end-of-stream iterator. Dereferencing or incrementing it further invokes undefined behavior.std::istreambuf_iterator
有一个简单的拷贝构造函数,一个constexpr的默认构造函数,一个平凡的析构函数.原文:
std::istreambuf_iterator
has a trivial copy constructor, a constexpr default constructor, and a trivial destructor.目录 |
[编辑] 会员类型
会员类型
|
Definition |
char_type
|
CharT
|
traits_type
|
Traits
|
int_type
|
typename traits::int_type |
streambuf_type
|
std::basic_streambuf<CharT, Traits> |
istream_type
|
std::basic_istream<CharT, Traits> |
本章尚未完成 原因:the proxy member type |
[编辑] 成员函数
构造一个新istreambuf_iterator 原文: constructs a new istreambuf_iterator (公共成员函数) | |
(destructor) (隐式声明) |
destructs an istreambuf_iterator (公共成员函数) |
(C++11 起) |
获得的电流的副本character accesses的当前字符的成员,如果 CharT 有成员 原文: obtains a copy of the current character accesses a member of the current character, if CharT has members (公共成员函数) |
推进istreambuf_iterator (公共成员函数) | |
如果两个istreambuf_iterators是流结束或如果两者都有效的测试 原文: tests if both istreambuf_iterators are end-of-stream or if both are valid (公共成员函数) |
[编辑] 非成员函数
比较2 istreambuf_iterators (函数模板) |
Inherited from std::iterator
Member types
会员类型
|
Definition |
value_type
|
CharT |
difference_type
|
Traits::off_type |
pointer
|
/* unspecified, usually CharT* */ |
reference
|
CharT |
iterator_category
|
std::input_iterator_tag |
[编辑] 示例
#include <vector> #include <sstream> #include <iostream> #include <iterator> int main() { // typical use case: an input stream represented as a pair of iterators std::istringstream in("Hello, world"); std::vector<char> v( (std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>() ); std::cout << "v has " << v.size() << " bytes. "; v.push_back('\0'); std::cout << "it holds \"" << &v[0] << "\"\n"; // demonstration of the single-pass nature std::istringstream s("abc"); std::istreambuf_iterator<char> i1(s), i2(s); std::cout << "i1 returns " << *i1 << '\n' << "i2 returns " << *i2 << '\n'; ++i1; std::cout << "after incrementing i1, but not i2\n" << "i1 returns " << *i1 << '\n' << "i2 returns " << *i2 << '\n'; ++i2; // this makes the apparent value of *i2 to jump from 'a' to 'c' std::cout << "after incrementing i2, but not i1\n" << "i1 returns " << *i1 << '\n' << "i2 returns " << *i2 << '\n'; }
输出:
v has 12 bytes. it holds "Hello, world" i1 returns a i2 returns a after incrementing i1, but not i2 i1 returns b i2 returns a after incrementing i2, but not i1 i1 returns b i2 returns c
[编辑] 另请参阅
输出迭代器,写入std::basic_streambuf 原文: output iterator that writes to std::basic_streambuf (类模板) | |
输入迭代器,读取std::basic_istream 原文: input iterator that reads from std::basic_istream (类模板) |