📄 funs.cpp
字号:
#include "funs.h"
//将字符串格式的日期转换成整形的日期----------------------------------
bool sdate2date(const string& sdate, int& year, int& month, int& day)
{
if ( sdate.length()!=10 || sdate[4]!='/' || sdate[7]!='/' )
{
return false;
}
year = atoi( sdate.substr(0,4).c_str() );
month = atoi( sdate.substr(5,2).c_str() );
day= atoi( sdate.substr(8,2).c_str() );
if ( year==0 || month==0 || day==0 )
{
return false;
}
return true;
}
//sdate2date结束-----------------------------------------------------------
//从键盘输入得到日期getdate-----------------------------------------
void getdate(int& year,int& month,int& day)
{
string sdate;
cout << "请输入日期,格式为年份(四位)/月份(二位)/天数(二位)"
<< "例如:1900/01/01\n";
do
{
fflush(stdin);
cin >> sdate;
if ( sdate2date(sdate, year, month, day) )
{
break;
}
else
{
cout << "您输入的字符不合法或日期格式不正确,请重新输入\n";
continue;
}
}while(true);
}
//getdate结束--------------------------------------------------------
//gettype(int t)-----------------------------------------------------
int gettype()
{
int type;
cout << "请选择日期输出格式(1~3),3种格式供的选择分别为:\n"
<< "1: year/month/day,如1900/01/01\n"
<< "2: year-month-day,如1900-01-1\n"
<< "3: year年month月day天,如1900年01月01日\n";
do
{
fflush(stdin);
cin.clear();
cin >> type;
if( cin.fail() )
{
cout << "您输出字符不合法,请重新输入要选择的日期格式\n";
continue;
}
if( type!=1 && type!=2 && type!=3 )
{
cout << "您选择的格式不正确,且只有1~3种格式选择,请重新输入\n";
continue;
}
break;
}while(true);
return type;
}
//gettype()结束-------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -