出错好几次终于搞定了,发个文章鼓励下自己,加油
![得意](http://static.blog.csdn.net/xheditor/xheditor_emot/default/proud.gif)
#include<string>
#include<iostream>
using std::string; using std::stoul;
using std::cout;
#include<string>
using std::string; using std::stoul;
class Riqi {
private:
unsigned long year, month, date;
public:
Riqi(): year(0), date(0) {}
Riqi(string s) {
if (!s.empty())
{
auto pos = s.find_last_of("1234567890");
year = stoul(s.substr(pos - 3));
s.erase(pos - 3);
if (s.find_first_of("QWERTYUIOPASDFGHJKLZXCVBNM") != string::npos) {
date = stoul(s.substr(s.find_first_of("1234567890")));
string str(s, 0, 3);
switch (s[0]) {
case 'J':
if (str == "Jan")
month = 1;
else if (str == "Jun")
month = 6;
else
month = 7;
break;
case'F':
month = 2;
break;
case'M':
if (str == "Mar")
month = 3;
else
month = 5;
break;
case'A':
if (str == "Apr")
month = 4;
else
month = 8;
break;
case'S':
month = 9;
break;
case'O':
month = 10;
break;
case'N':
month = 11;
break;
case'D':
month = 12;
break;
}
}
else {
month = stoul(s);
if (month > 9)
date = stoul(s.substr(3));
else
date = stoul(s.substr(2));
}
}
}
void Print() {
cout << year << " " << month << " " << date << "\n";
}
};
int main()
{
//*
Riqi v1("January 1,1900"), v2("Feb 20,1909"), v3("23/23/1999"), v4("1 2 1987");
v1.Print();
v2.Print();
v3.Print();
v4.Print();
//*/
system("pause");
return 0;
}