Defined in header <iterator>
    template< class T, class CharT = char, class Traits = std::char_traits<CharT>>
          class ostream_iterator : public std::iterator<std::output_iterator_tag, void, void, void, void>

std::ostream_iterator is a single-pass OutputIterator that writes successive objects of type T into thestd::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.

In a typical implementation, the only data members of std::ostream_iterator are a pointer to the associatedstd::basic_ostream and a pointer to the first character in the delimiter string.

When writing characters, std::ostreambuf_iterator is more efficient, since it avoids the overhead of constructing and destructing the sentry object once per character.

 #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, " "));
}

Output:

0.1 0.3 0.6 1
 // ostream_iterator example
#include <iostream> // std::cout
#include <iterator> // std::ostream_iterator
#include <vector> // std::vector
#include <algorithm> // std::copy int main () {
std::vector<int> myvector;
for (int i=; i<; ++i) myvector.push_back(i*); std::ostream_iterator<int> out_it (std::cout,", ");
std::copy ( myvector.begin(), myvector.end(), out_it );
return ;
}
Output:
   10, 20, 30, 40, 50, 60, 70, 80, 90,

std::ostream_iterator用法的更多相关文章

  1. c++ std::string 用法

    std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...

  2. c/c++ 多线程 等待一次性事件 std::promise用法

    多线程 等待一次性事件 std::promise用法 背景:不是很明白,不知道为了解决什么业务场景,感觉std::async可以优雅的搞定一切的一次等待性事件,为什么还有个std::promise. ...

  3. std::map用法

    STL是标准C++系统的一组模板类,使用STL模板类最大的好处就是在各种C++编译器上都通用.    在STL模板类中,用于线性数据存储管理的类主要有vector, list, map 等等.本文主要 ...

  4. std::string 用法总结

    标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...

  5. std::string 用法

    string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初始化 string类的字符操作:const ...

  6. C/C++ C++ 11 std::function和std::bind用法

    std::bind() std::bind 主要用于绑定生成目标函数,一般用于生成的回调函数,cocos的回退函数都是通过std::bind和std::function实现的.两个点要明白: 1.绑定 ...

  7. codeforces-Glass Carving(527C)std::set用法

    C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  8. C++11 std::function用法

    转自 http://www.hankcs.com/program/cpp/c11-std-function-usage.html function可以将普通函数,lambda表达式和函数对象类统一起来 ...

  9. 模板std::mutex用法:

    std::mutex mymutex; std::lock_guard<std::mutex> lock(mymutex);

随机推荐

  1. C# 获取图片某像素点RGB565值

    Project Source Download: http://download.csdn.net/detail/mostone/6360007 [csharp] view plain copy pu ...

  2. [mpm_winnt:error] [pid 28120:tid 15980] (OS 10038)在一个非套接字上尝试了一个操作。 : AH00332: winnt_accept: getsockname error on listening socket, is IPv6 available?

    解决办法一: 可能是安装了某些程序修改了Winsock,使用netsh winsock reset 命令修复Winsock重启计算机即可! 解决办法二: 在httpd.conf文件中添加 Win32D ...

  3. Java更新

    Java I/O 总结 JVM(8):JVM知识点总览-高级Java工程师面试必备 细数JDK里的设计模式 Java中创建对象的5种不同方法 关于Java Collections的几个常见问题 类在什 ...

  4. <c:set var="ctx" value="${pageContext.request.contextPath}" />的学习

    ${pageContext.request.contextPath},是获取当前根目录 set var="ctx",是给这个路径定义了一个变量,用的时候可以通过EL表达式获取:${ ...

  5. 关于taskaffinity属性的作用

    意味着这activity更喜欢哪个TESK,具体见下方说明 当一个包含FLAG_ACTIVITY_NEW_TASK标志的intent启动一个activity时. 一个新的activity,默认地启动到 ...

  6. 第3章_Java仿微信全栈高性能后台+移动客户端

    当服务器构建完毕并且启动之后,我们通过网页URL地址就可以访问这台服务器,并且服务器会向网页输出Hello Netty这样几个字. Netty有三种线程模型:单线程.多线程.主从线程.Netty官方推 ...

  7. 第3章 springboot接口返回json 3-2 Jackson的基本演绎法

    @JsonIgnore private String password; @JsonFormat(pattern="yyyy-MM-dd hh:mm:ss a",locale=&q ...

  8. js面试题知识点全解(一闭包)

    闭包使用场景:1.函数作为返回值,如下场景 function F1(){ var a = 100 //自由变量 //返回一个函数(函数作为返回值) return function(){ console ...

  9. 使用Java建立聊天客户端

    ---------------siwuxie095                             关于 聊天服务器,详见本人博客的分类:来一杯Java, 里面的 使用ServerSocket ...

  10. Python 网络爬虫 002 (入门) 爬取一个网站之前,要了解的知识

    网站站点的背景调研 1. 检查 robots.txt 网站都会定义robots.txt 文件,这个文件就是给 网络爬虫 来了解爬取该网站时存在哪些限制.当然了,这个限制仅仅只是一个建议,你可以遵守,也 ...