永发信息网

判断字符串是否为日期 c++

答案:2  悬赏:80  手机版
解决时间 2021-01-28 05:12
  • 提问者网友:椧運幽默
  • 2021-01-27 14:59
判断字符串是否为日期 c++
最佳答案
  • 五星知识达人网友:纵马山川剑自提
  • 2021-01-27 16:28
日期字符串有格式,下面为14码格式的代码……
//#include "stdafx.h"//vc++6.0加上这一行.
#include
using namespace std;
void main(void){
int year,month,day,h,m,s;
char tm[]="20080326082708",md[]={31,28,31,30,31,30,31,31,30,31,30,31};
year=(tm[0]&15)*1000+(tm[1]&15)*100+(tm[2]&15)*10+(tm[3]&15);
month=(tm[4]-'0')*10+(tm[5]-'0');
day=(tm[6]-'0')*10+(tm[7]-'0');
h=(tm[8]-'0')*10+(tm[9]-'0');
m=(tm[10]-'0')*10+(tm[11]-'0');
s=(tm[12]-'0')*10+(tm[13]-'0');
if(year%400==0 || year%4==0 && year%100!=0) md[1]=29;
else md[1]=28;
if(strlen(tm)==14 && year>0 && year<10000 && month>0 && month<13 && day>0
&& day<=md[month-1] && h>=0 && h<24 && m>=0 && m<60 && s>=0 && s<60)
cout << "It is the date string.\n";
else cout << "It is not!\n";
}
全部回答
  • 1楼网友:洒脱疯子
  • 2021-01-27 16:33
c++中判断字符串是否为空格的方法: ifstream infile("xxx.txt",ios::in); while(!infile.eof()){ infile>>c; while( (c!=' ') && (c!='\t') && (c!='\n') ){ //这里是过滤字符的核心。 word[pos]=c; pos++; infile>>c; } word[pos]='\0'; if(pos!=0){ cout<
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯