#include
using namespace std ;
typedef struct
{
int year ;
int month ;
int day;
int hour ;
int minute ;
int second ;
} Time ;
int main()
{
Time *time = new Time() ;
cout << "请输入年:" ;
cin >> time->year ;
cout << "请输入月:";
cin >> time->month ;
cout << "请输入日:";
cin >> time->day ;
cout << "请输入时:";
cin >> time->hour ;
cout << "请输入分钟:" ;
cin >> time->minute ;
cout << "请输入秒:" ;
cin >> time->second ;
//Display
cout << time->year << " 年 " << time->month << " 月 " << time->day << " 日 "
<< time->hour << " 时 " << time->minute << " 分 " << time->second << " 秒" << endl ;
return 0 ;
}
#include
void main()
{
int year,month,day,hour,sec,miu;
printf("输入年:");scanf("%d",&year);
printf("输入月:");scanf("%d",&month);
printf("输入日:");scanf("%d",&day);
printf("输入时:");scanf("%d",&hour);
printf("输入分:");scanf("%d",&sec);
printf("输入秒:");scanf("%d",&miu);
printf("输入的日期为:%d年%d月%d日 %d:%d:%d",year,month,day,hour,sec,miu);
}
#include
typedef struct time
{
int year,month,day,hour,sec,miu;
}time;
void main()
{
time test;
cout<<"输入年:"<
cout<<"输入月:"<
cout<<"输入日:"<
cout<<"输入时:"<
cout<<"输入分钟:"<
cout<<"输入秒:"<
cout<<"您输入的日期为:"<
}
#include
using namespace std;
struct time{
int y;
int m;
int d;
int h;
int mi;
int sec;};
int input();
int main()
{
time newtime;
cout<<"输入年:\n";
newtime.y=input();
cout<<"输入月:\n";
newtime.m=input();
cout<<"输入日:\n";
newtime.d=input();
cout<<"输入时:\n";
newtime.h=input();
cout<<"输入分:\n";
newtime.mi=input();
cout<<"输入秒:\n";
newtime.sec=input();
cout<<"你输入的是:"<
}
int input()
{
int temp;
while(!(cin>>temp))
{
cin.clear();
while(cin.get()!='\n')
continue;
cout<<"请输入数字!\n";
}
return temp;
}
当输入非数值时会报警。
#include
using namespace std;
struct Time{
short year,month,day,hour,minute,second;
void SetTime();
void Print();
};
void Time::SetTime()
{
cout<<"set year:"; cin>>year;
cout<<"set month:"; cin>>month;
cout<<"set day:"; cin>>day;
cout<<"set hour:"; cin>>hour;
cout<<"set minute:"; cin>>minute;
cout<<"set second:"; cin>>second;
}
void Time::Print()
{
cout<<"The time is:";
cout<
int main()
{
Time TIME;
cout<<"Set Time\n";
TIME.SetTime();
TIME.Print();
return 0;
}