std::istream_iterator
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <iterator> 中定义
|
||
template< class T, class CharT = char, |
||
std::istream_iterator
是单通输入迭代器,读取连续的T
类型的对象从std::basic_istream对象,它被修建了,通过调用相应的operator>>
的。实际的读操作时执行的迭代器是递增的,而不是当它被废弃。该迭代器时建造或完成的第一个间接引用,可以读出的第一个对象。否则,只提领返回最近读的对象的副本.原文:
std::istream_iterator
is a single-pass input iterator that reads successive objects of type T
from the std::basic_istream object for which it was constructed, by calling the appropriate operator>>
. The actual read operation is performed when the iterator is incremented, not when it is dereferenced. The first object 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 object.被称为“流”迭代器的默认构造
std::istream_iterator
。当一个有效的std::istream_iterator
达到基础流的结束,它变得等于最终的流迭代器。提领或递增的进一步调用未定义的行为.原文:
The default-constructed
std::istream_iterator
is known as the end-of-stream iterator. When a valid std::istream_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::istream_iterator
持有两个数据成员:一个指针,指向相关的std::basic_istream对象,最近读的类型的值T
.原文:
A typical implementation of
std::istream_iterator
holds two data members: a pointer to the associated std::basic_istream object and the most recently read value of type T
.读取字符时,std::istreambuf_iterator是更有效的,因为它避免了一次,每个字符建设和破坏的哨兵对象的开销.
原文:
When reading characters, std::istreambuf_iterator is more efficient, since it avoids the overhead of constructing and destructing the sentry object once per character.
目录 |
[编辑] 会员类型
会员类型
|
Definition |
char_type
|
CharT
|
traits_type
|
Traits
|
istream_type
|
std::basic_istream<CharT, Traits> |
[编辑] 成员函数
构造一个新的istream_iterator (公共成员函数) | |
(destructor) (隐式声明) |
destructs an istream_iterator, including the cached value (公共成员函数) |
获得的电流的副本element accesses当前元素的成员 原文: obtains a copy of the current element accesses a member of the current element (公共成员函数) | |
推进istream_iterator (公共成员函数) |
[编辑] 非成员函数
比较2 istream_iterators (函数模板) |
Inherited from std::iterator
Member types
会员类型
|
Definition |
value_type
|
T |
difference_type
|
Distance |
pointer
|
const T* |
reference
|
const T& |
iterator_category
|
std::input_iterator_tag |
[编辑] 示例
#include <iostream> #include <sstream> #include <iterator> #include <numeric> int main() { std::istringstream str("0.1 0.2 0.3 0.4"); std::partial_sum(std::istream_iterator<double>(str), std::istream_iterator<double>(), std::ostream_iterator<double>(std::cout, " ")); }
输出:
0.1 0.3 0.6 1
[编辑] 另请参阅
输出迭代器,写入std::basic_ostream 原文: output iterator that writes to std::basic_ostream (类模板) | |
输入迭代器,读取std::basic_streambuf 原文: input iterator that reads from std::basic_streambuf (类模板) |