std::ostream_iterator
来自cppreference.com
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| 在头文件 <iterator> 中定义
|
||
| template< class T, class CharT = char, |
||
std::ostream_iterator是单通输出迭代器,写入连续T对象,它构建了std::basic_ostream类型的对象,使用operator<<。每次写操作后,可选分隔符的字符串写入到输出流。写操作被执行时的迭代器(是否解除引用或不)被分配到。递增std::ostream_iterator是一个no-op.原文:
std::ostream_iterator is a single-pass output iterator that writes successive objects of type T into the std::basic_ostream object for which it was constructed, using operator<<. Optional delimiter string is written to the output stream after every write operation. The write operation is performed when the iterator (whether dereferenced or not) is assigned to. Incrementing the std::ostream_iterator is a no-op.在典型的应用中,只有数据成员
std::ostream_iteratorstd::basic_ostream和分隔符的字符串中的第一个字符指针的指针.原文:
In a typical implementation, the only data members of
std::ostream_iterator are a pointer to the associated std::basic_ostream and a pointer to the first character in the delimiter string.当练字,std::ostreambuf_iterator是更有效的,因为它避免了一次,每个字符建设和破坏的哨兵对象的开销.
原文:
When writing characters, std::ostreambuf_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
|
ostream_type
|
std::basic_ostream<CharT, Traits> |
[编辑] 成员函数
| 构造一个新ostream_iterator连用 (公共成员函数) | |
| 解构ostream_iterator连用 (公共成员函数) | |
| 写入一个对象相关联的输出序列 原文: writes a object to the associated output sequence (公共成员函数) | |
| no-op (公共成员函数) | |
| no-op (公共成员函数) | |
Inherited from std::iterator
Member types
| 会员类型
|
Definition |
value_type
|
void |
difference_type
|
void |
pointer
|
void |
reference
|
void |
iterator_category
|
std::output_iterator_tag |
[编辑] 示例
#include <iostream> #include <sstream> #include <iterator> #include <algorithm> 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_streambuf 原文: output iterator that writes to std::basic_streambuf (类模板) | |
| 输入迭代器,读取std::basic_istream 原文: input iterator that reads from std::basic_istream (类模板) | |