接受一个日期的构造函数
来源:互联网 发布:小米盒子软件大全 编辑:程序博客网 时间:2024/06/18 12:07
C++ Primer 5th 9.51
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
struct Date
{
unsigned year;
unsigned month;
unsigned day;
string theyear;
string themonth;
string theday;
string number{ "0123456789" };
string separated{ " /" };
vector<string> monthsOne{ "January","February","March","April","May" ,"June" ,"July" ,"August" ,"September", "October", "November" ,"December" };
vector<string> monthsTwo{ "Jan","Feb","Mar","Apr","May", "Jun" ,"July" ,"Aug" ,"Sep" ,"Oct", "Nov" ,"Dec" };
Date(string &s)
{
string::iterator begin=s.begin();
string::iterator end = s.begin();
int pos = 0;
pos = s.find_first_of(separated,pos);
end =s.begin()+ pos;
themonth.assign(begin, end);
begin = end + 1;
pos = s.find_first_of(separated, pos + 1);
end = s.begin() + pos;
theday.assign(begin, end);
begin = end + 1;
end = s.end();
theyear.assign(begin, end);
year = stod(theyear);
day = stod(theday);
if (themonth.find_first_of(number) != -1)
{
month = stod(themonth);
}
else
{
int i;
for(i = 0;i!=12;i++)
{
if (themonth == monthsOne[i])
{
month = i + 1;
break;
}
}
if (i == 12)
{
for (i = 0; i != 12; i++)
{
if (themonth == monthsTwo[i])
{
month = i + 1;
break;
}
}
}
}
}
};
int main()
{
string s;
getline(cin, s);
Date theDate(s);
cout << "年份是:" << theDate.year<<endl;
cout << "月份是:" << theDate.month << endl;
cout << "天数是:" << theDate.day << endl;
system("pause");
return 0;
}
坑真的太多,以后再来填...
- 接受一个日期的构造函数
- 一个可靠的发送和接受数据函数
- 创建一个接受String或&str的Rust函数
- 一个仅接受两个输入向量的协方差计算函数
- 2.14 构造一个DFA,它接受Σ = {0,1}上能被5整除的二进制数。
- 一个构造url编码链接的函数
- c++默认构造函数的一个问题
- 如何构造一个平滑的最大值函数
- 关于拷贝构造函数的一个问题
- 构造函数的一个小错误
- 一个关于构造函数的笔试题
- 如何调用一个对象的构造函数
- 一个js构造树的函数
- 构造函数的一个小问题
- 一个比较日期大小的javascript函数
- 一个日期时间比较的函数
- 一个关于计算出日期差距的函数
- sort()接受一个函数方法进行排序
- 根据经纬度计算地图上两点的距离
- ES6中class原理,static属性方法,__proto__与prototype深入分析
- alignSelf
- fastjson中$ref对象重复引用问题解决方法
- 调试Devc++
- 接受一个日期的构造函数
- OpenXML SDK 读取WORD文档中的内容控件
- mysql 实现主从双向同步
- 揭开伪基站的神秘面纱
- JDBC浅析
- esxi
- 单例模式
- 微信小程序tabBar底部导航 不显示问题解析
- 基于Openfire Smack开发即时通讯应用、获取所有群组、加入群聊、创建群组(四)