首页 技术 正文
技术 2022年11月17日
0 收藏 346 点赞 3,753 浏览 1082 个字
#include<iostream>
#include<sstream> //使用istringstream必须包含的头文件
#include<string>
#include<stdlib.h>
#include<vector>
using namespace std;//模板函数:将string类型变量转换为常用的数值类型 by maowei
template <class Type>
Type stringToNum(const string& str)
{
istringstream iss(str);
Type num;
iss>>num;
return num;
}int main(int argc,char *argv[]){
string com;
vector<string> info();
getline(cin,com);
int start=,end=;//手工编写解读字符串信息的函数
while(start!=string::npos&&start!=com.size()){
start=com.find_first_not_of(' ',start);
end=com.find_first_of(' ',start);
if(end==string::npos){end=com.size();}
info.push_back(com.substr(start,end-start));
start=end;
}
cout<<"info_size="<<info.size()<<endl;
cout<<"info_capacitity="<<info.capacity()<<endl;
for(int j=;j<info.size();++j)cout<<info[j]<<endl;//test_template
string s="";
double x = stringToNum<double>(s);
cout<<"x="<<x<<endl;vector<string> info_1;istringstream is(com);//采用istringstream从string对象str中读取字符
string s2;
while(is>>s2){cout<<s2<<endl;info_1.push_back(s2);}cout<<"info_1_size="<<info_1.size()<<endl;
cout<<"info_1_capacitity="<<info_1.capacity()<<endl;
for(int j=;j<info.size();++j)cout<<info_1[j]<<endl; return ;
}

字符串处理——(第一次作业Draw输入命令处理部分升级)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,089
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,566
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,415
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,187
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,823
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,906