?? 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 + -