sstream.h的使用 以一个计算时间的程序为例子
来源:互联网 发布:js隐藏元素 编辑:程序博客网 时间:2024/04/29 09:12
sstream是c++引入流的概念,让各种数据转换起来容易 主要使用方法
sstream ss;
int number;
string s="123";
ss>>s;
ss<<number;
在使用使要注意在此使用使需要清空流中的数据 使用str("")以及clear()
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <sstream>
usingnamespacestd;
struct travel_time
{
int hours;
int mins;
};
travel_time sum(travel_time t1,travel_time t2)
{
travel_time t3;
int tt3 =fabs(t1.hours*60+t1.mins-(t2.hours*60+t2.mins));
t3.hours=tt3/60;t3.mins=tt3%60;
return t3;
}
void show_time(travel_time t)
{
cout<<t.hours<<"hs "<<t.mins<<"mins"<<endl;
}
int main(){
string s ,a,b;
stringstream s1,s2;
cout<<"Enter t1(2-30):";
cin>>s;
int count =0;
for(int i=0;i<s.length();i++)
{
if(s[i]>='0'&&s[i]<='9'&&count==0)
a+=s[i];
if(s[i]=='-')
count++;
if(count!=0)
{
if(s[i]>='0'&&s[i]<='9')
b+=s[i];
}
}
travel_time t1,t2{1,50};
s1<<a;
s2<<b;
s1>>t1.hours;
s2>>t1.mins;
show_time(sum(t1, t2));
return0;
}
- sstream.h的使用 以一个计算时间的程序为例子
- 一个计算开机时间的小程序
- 计算一个程序的运行时间
- 计算一个程序的运行时间
- sstream与相比stdio.h的好处
- 递归思想分析----以一个简单的例子为例
- php计算程序运行时间的简单例子分享
- sstream 与 fstream的使用
- sscanf和sstream的使用
- 以面向对象方式编写一个计算电话费的程序
- 使用Stopwatch计算程序运行的时间
- 怎样使用字体图标,以淘宝的图标为例子
- 计算一个方法使用的时间
- 计算程序的时间
- 使用线程的一个例子程序
- 编写一个以C 语言为基础的DSP程序
- 编写一个以C 语言为基础的DSP程序
- 微信小程序例子——使用画布组件绘制一个半径为50px的圆
- MyEclipse 远程调试Tomcat
- angular查询(回车)
- 用xPath查询标签
- ES基本搜索功能
- 实现在html页面加载之前执行js方法
- sstream.h的使用 以一个计算时间的程序为例子
- xml读取异常Invalid byte 1 of 1-byte UTF-8 sequence
- Mvp解耦
- 分页插件pagehelper的使用
- XListview刷新
- 基础数据机构之Stack栈源码分析
- Python资料之fileinput模块
- 封装RunOnUIThread方法
- Android深入分析MessageQueue和Looper(FrameWork JAVA部分)