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

#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输入命令处理部分升级)

上一篇:网络&热恋NSURLConnection代理及GET¥POST请求


下一篇:完美解决:Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=6&arch=x