//用 getline 函数从输入读取整行内容。然后为了获得每行中的单词,将一个 //istringstream 对象与所读取的行绑定起来,这样只需要使用普通的 //string 输入操作符即可读出每行中的单词。 string line, word;// will hold a line and word from input, rectively while (getline(cin, line)) { // read a line from the input into line // do per-line processing istringstream stream(line); // bind to stream to the line we read while (stream >> word) { // read a word from line // do per-word processing } }
//stringstream 对象的一个常见用法是,需要在多种数据类型之间实现自动格式化时 //使用该类类型 int val1 = 512, val2 = 1024; ostringstream format_message; // ok: converts values to a string representation format_message << "val1: " << val1 << "\n" << "val2: " << val2 << "\n"; //相反,用 istringstream 读 string 对象,即可重新将数值型数据找回来 istringstream input_istring(format_message.str()); string dump; // place to dump the labels from the formatted message input_istring >> dump >> val1 >> dump >> val2; cout << val1 << " " << val2 << endl; // prints 512 1024
发表评论
-
const 与static 关键词在c 和 c++中的作用
2012-08-11 11:49 967一.C语言中的const ... -
error LNK2005 and error LNK2019
2012-08-09 23:08 1098error LNK2005 and error LNK2019 ... -
LIBCD.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSV
2012-08-07 09:20 1385LIBCD.lib(crt0dat.obj) : error ... -
在VS2010下配置VC++ Directories
2012-08-07 08:29 10461:可以 在“class View” 面板 -> 右 ... -
VC: error LNK2019:unresolved external symbol *** referenced in function ***的解决方案
2010-10-30 21:13 2108当头文件中声明了一个函数,但是在相应的源文件中却没有对该函数进 ... -
stdcall cdecl fastcall thiscall naked call的具体含义
2010-10-30 18:54 960在C语言中,假设我们有 ... -
#define总结 (网上资料汇集)
2010-10-30 08:06 7161. 定义简单的常数:定义常量,便于修改(切不可在后面加上分号 ... -
(zz)编译与使用Qt4,Visual Studio Express 2008
2010-10-14 22:35 1375一、Qt版本 我现在用的是4.5.2。好像前段时间4.6出来 ... -
strcat 内部实现
2010-09-21 00:43 1799char * strcat(char * dest, ... -
deep copy & shallow copy
2010-09-15 19:27 817A shallow copy of an object cop ... -
reinterpret_cast的本质(转)
2010-09-14 23:15 1615先看看下面的代码: #include <iostr ... -
C++ 经典书籍
2010-09-14 16:18 1684下载地址: http://www.51cnnet.net/di ... -
内存对齐的规则以及作用
2010-09-14 00:14 687首先由一个程序引入话 ... -
[转]C++ reinterpret_cast,const_cast等 显式类型转换总结
2010-09-13 23:23 1012#include<iostream.h> ... -
C++提供了四种新的类型强制
2010-09-13 23:13 686static_cast const_cast reinte ... -
C++著名程序库的比较和学习经验
2010-09-13 19:30 8251、C++各大有名库的介绍——C++标准库 2、C++各大有名 ... -
c++ library and resource List
2010-09-13 18:56 8991,前言 无数次听 ... -
C++中操作符operator的两种用法
2010-09-12 02:23 11171.operator overloading C++可能通过o ... -
两种自动类型转换:构造函数与operator
2010-09-12 02:23 890如果有两个对象:one, two, 要想把one转换成为two ... -
C++中的类拷贝构造函数和模板拷贝构造函数
2010-09-11 20:53 3002类(包括模板类)构造函数是真实的构造函数;然而模板构造函数,其 ...
相关推荐
汉字零星整理及应用,研究汉字的设计,字体的设计,韵律等
2020年零星维修项目投标文件.pdf2020年零星维修项目投标文件.pdf2020年零星维修项目投标文件.pdf2020年零星维修项目投标文件.pdf2020年零星维修项目投标文件.pdf
零星维修项目投标文件.pdf
医院零星维修管理制度
零星工程安全交底记录表
零星工程验收单.pdf
土建、装饰、维修改造等零星的工程施工组织设计技术标.pdf
零星雨控制软件,LED控制卡控制软件的安装程序
第三方零星维修清单
公司企业零星采购管理办法.pdf
煤矿零星事故大多是发生在零星岗位和零散作业过程中,控制零星事故的发生对于煤矿实现"零死亡"目标具有极其重要的作用。加强对零星岗位的培训、教育和有效管理,开展零星岗位安全整顿,提高其思想业务素质,逐步规范其...
零星维修工程施工方案.pdf
零星费用支付申请单.doc
煤矿零星工程管理制度汇编.doc
XX大学房屋零星装修、改造工程申请表.pdf
小区零星维修项目施工组织计划.doc
零星工程框架协议(修改).pdf
E扩展程序,有利于e仅筋计算,....以及钢筋计算
浅议电网企业零星物资电商化采购策略.pdf
参考资料-9-10零星工程施工监理.doc