首页 新闻 会员 周边

有关于类型转换的 无运行结果啊 求解

0
[待解决问题]

放在这格式有点难看

#include<iostream>
#include<string>
#include<vector>

using namespace std;
class Date
{
public:
unsigned year;
unsigned month;
unsigned day;
Date(string s);
void show(){
cout<<month<<"月"<<day<<"日"<<year<<"年"<<endl;
};
};

Date::Date(string s){
string number="1234567890/";
string came=",";
string _month;
unsigned pos,pos1,pos2,pos3;
unsigned _pos,_pos1,_pos2;
int flag=0;
if((pos=s.find_first_not_of(number))==string::npos){
flag=1;
}
if((pos=s.find_first_of(came)!=string::npos)){
flag=2;
}
switch(flag){
case 2://首先处理January 1,1900 格式
pos1=0;
pos1=s.find_first_of(number);
_month=s.substr(0,pos1);
if (_month == "January ") month = 1;
if (_month == "April ") month = 4;
if (_month == "May ") month = 5;
if (_month == "June ") month = 6;
if (_month == "July ") month = 7;
if (_month == "August ") month = 8;
if (_month == "September ") month = 9;
if (_month == "October ") month = 10;
if (_month == "November ") month = 11;
if (_month == "December ") month = 12;
pos2=pos1++;
pos1=s.find_first_of(came,pos1);
day=stoul(s.substr(pos2-1,pos1));
pos3=pos1++;
year=stoul(s.substr(pos3,s.size()-1));
break;
case 1:
//处理1/1/1900数据
_pos=0;
_pos=s.find_first_of("/",_pos);
month=stoul(s.substr(0,_pos));
_pos1=++_pos;
_pos=s.find_first_of("/",_pos1);
day=stoul(s.substr(_pos1,_pos));
_pos2=_pos++;
year=stoul(s.substr(_pos2,s.size()-1));
break;
case 0:
//处理Jan 1 1900数据
_pos=0;
_pos=s.find_first_of(number);
_month=s.substr(0,_pos);
if (_month == "Jan ") month = 1;
if (_month == "Feb ") month = 2;
if (_month == "Mar ") month = 3;
if (_month == "Apr ") month = 4;
if (_month == "May ") month = 5;
if (_month == "Jun ") month = 6;
if (_month == "Jul ") month = 7;
if (_month == "Aug ") month = 8;
if (_month == "Sep ") month = 9;
if (_month == "Oct ") month = 10;
if (_month == "Nov ") month = 11;
if (_month == "Dec ") month = 12;
_pos1=_pos++;
_pos=s.find_first_of(number,_pos);
day=stoul(s.substr(_pos1-1,_pos));
year=stoul(s.substr(_pos,s.size()-1));
break;
}
}

int main(){

Date _today("1/1/1900");
_today.show();
return 0;
}

渣渣鸽的主页 渣渣鸽 | 菜鸟二级 | 园豆:202
提问于:2017-03-11 14:50
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册