std::ostream_iterator用法
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用法的更多相关文章
- c++ std::string 用法
std::string用法总结 在平常工作中经常用到了string类,本人记忆了不好用到了的时候经常要去查询.在网上摘抄一下总结一下,为以后的查询方便: string类的构造函数: string(co ...
- c/c++ 多线程 等待一次性事件 std::promise用法
多线程 等待一次性事件 std::promise用法 背景:不是很明白,不知道为了解决什么业务场景,感觉std::async可以优雅的搞定一切的一次等待性事件,为什么还有个std::promise. ...
- std::map用法
STL是标准C++系统的一组模板类,使用STL模板类最大的好处就是在各种C++编译器上都通用. 在STL模板类中,用于线性数据存储管理的类主要有vector, list, map 等等.本文主要 ...
- std::string 用法总结
标准C++中的string类的用法总结 相信使用过MFC编程的朋友对CString这个类的印象应该非常深刻吧?的确,MFC中的CString类使用起来真的非常的方便好用.但是如果离开了MFC框架,还有 ...
- std::string 用法
string类的构造函数:string(const char *s); //用c字符串s初始化string(int n,char c); //用n个字符c初始化 string类的字符操作:const ...
- C/C++ C++ 11 std::function和std::bind用法
std::bind() std::bind 主要用于绑定生成目标函数,一般用于生成的回调函数,cocos的回退函数都是通过std::bind和std::function实现的.两个点要明白: 1.绑定 ...
- codeforces-Glass Carving(527C)std::set用法
C. Glass Carving time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- C++11 std::function用法
转自 http://www.hankcs.com/program/cpp/c11-std-function-usage.html function可以将普通函数,lambda表达式和函数对象类统一起来 ...
- 模板std::mutex用法:
std::mutex mymutex; std::lock_guard<std::mutex> lock(mymutex);
随机推荐
- MySQL 备份脚本--mysqldump在slave 上进行备份
MySQL 备份脚本--mysqldump在slave 上进行备份 使用mysqldump在slave上进行备份,建议使用stop slave sql_thread,start slave sql_t ...
- redis学习四 复制
1,单机创建多实例 一个redis服务器安装多个redis实例,每个实例对应一个端口.默认端口是6379. 将redis.conf配置文件复制一份到另外一个文件夹下,然后修改其中的信息即可. pi ...
- java 多线程系列基础篇(七)之线程休眠
1. sleep()介绍 sleep() 定义在Thread.java中.sleep() 的作用是让当前线程休眠,即当前线程会从“运行状态”进入到“休眠(阻塞)状态”.sleep()会指定休眠时间,线 ...
- css垂直居中方法(四)
第六种方法,使用css的writing-mode属性,结合margin:auto. 参考文章:改变CSS世界纵横规则的writing-mode属性 传统的web流中,margin设置auto值的时候, ...
- awk简要使用
1 前言 awk是Unix环境下一种非常好的语言,适合于文本处理和报表生成,它还有许多精心设计的特性,允许进行特殊技巧程序设计.对于短消息来说,比如处理话单文件,使用awk就非常方便 ...
- 登陆Oracle出现错误java.lang.exception
出现错误时登录企业管理器时出现的界面 出现这种错误一般是因为没有设置时区,一般默认的是agentTZRegion=GMT,也就是GMT.所以大家只要设置了这个东西,然后重新启动dbconsole就可以 ...
- MSSQL grant权限
--创建登录名 create login test_user with password='123456a.'; --创建用户 create user test_user for login test ...
- SQL查询语句 [1]
一.使用字符串作为条件查询 在 Home/controller/UserController.class.php 下插入 <?php namespace Home\Controller; use ...
- cocos2dx中的Rapidjson
1 Json基础 JSON 概念和特点: JSON 指的是 JavaScript 对象表示法(JavaScript Object Notation) JSON 是轻量级的文本数据交换格式,类似 XML ...
- C语言-郝斌笔记-004判断是否为回文数
判断是否为回文数 # include <stdio.h> int main(void) { int val; //存放待判断的数字 int m; ; printf("请输入您需要 ...