9.51 设计一类,它又三个unsigned成员,分别表示年月日。为其编写构造函数,接受一个表示日期的string参数。

程序如下:

#include<iostream>
#include<string>
using namespace std; class My_Date
{
public:
My_Date(const string &s);
unsigned year;
unsigned month;
unsigned day;
}; My_Date::My_Date(const string &s)
{
unsigned format=;
if(s.find_first_of("/")!=string::npos)
format=0x10;
if(s.find_first_of(",")!=string::npos)
format=0x01;
switch(format)
{
case 0x10:
day=stoi(s.substr(,s.find_first_of("/")));
month=stoi(s.substr(s.find_first_of("/")+,s.find_last_of("/")-s.find_first_of("/")));
year=stoi(s.substr(s.find_last_of("/")+,));
break;
case 0x01:
day=stoi(s.substr(s.find_first_of(""),s.find_first_of(",")-s.find_first_of("")));
if(s.find("Jan")<s.size()) month=;
if(s.find("Feb")<s.size()) month=;
if(s.find("Mar")<s.size()) month=;
if(s.find("Apr")<s.size()) month=;
if(s.find("May")<s.size()) month=;
if(s.find("Jun")<s.size()) month=;
if(s.find("Jul")<s.size()) month=;
if(s.find("Aug")<s.size()) month=;
if(s.find("Sep")<s.size()) month=;
if(s.find("Oct")<s.size()) month=;
if(s.find("Nov")<s.size()) month=;
if(s.find("Dec")<s.size()) month=;
year=stoi(s.substr(s.find_last_of(",")+,));
break;
}
}
int main()
{
My_Date d("99/21/1234");
cout<<d.day<<" "<<d.month<<" "<<d.year<<endl;
return ;
}

运行结果如下:

最新文章

  1. Linux 入门之修改主机名
  2. MySQL安装步骤
  3. linux允许80端口通过
  4. VPN有什么用?(转载)
  5. 最新AndroidSDK安装教程
  6. python中string.casefold和string.lower区别
  7. Noip2014 提高组 T2 联合权值 连通图+技巧
  8. Calculations are rather interesting
  9. oledb 操作 excel
  10. 实现windows和linux互传文件
  11. Java基础知识强化之IO流笔记10:File类输出指定目录下指定后缀名的文件名称案例(File类的文件过滤器方法改进list( FilenameFilter ff))
  12. C#中List&lt;T&gt;用法
  13. Ubuntu 13.04 小米2S连接Eclipse真机调试
  14. C++之static_cast, dynamic_cast, const_cast
  15. spring boot 下 500 404 错误页面处理
  16. mongodb笔记2
  17. php的mysql语句里变量加不加单引号问题
  18. Spring context:property-placeholder 一些坑
  19. Python:SQLMap源码精读—start函数
  20. [No0000141]Outlook,设置全局已读回执

热门文章

  1. 6个常见的 PHP 安全性攻击
  2. 【Python】代码行数统计
  3. 函数lock_mode_stronger_or_eq 锁权限等级
  4. C#中窗体的一些简单运用
  5. 转自 Because of you 的总结
  6. STSdb
  7. Oracle将英文字符集数据转换成中文
  8. 高并发的常见策略--大型web项目
  9. Mealy和moore型状态机
  10. 调试 Azure 云服务项目的方法