新手求思路,求指点。急!!谢谢!!!
声明一个表示时间的结构体,可以精确表示年,月,日,小时,分,秒;提示用户输入年,月,日,小时,分,秒的值,然后完整地显示出来。#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Time{
int year;
int month;
int day;
int hour;
int minute;
int second;
};
int main(){
int year,month,day,hour,minute,second;
Time ti={year,month,day,hour,minute,second};
cout<<"Year: "<<ti.year<<endl;
cout<<"Month: "<<ti.month<<endl;
cout<<"Day: "<<ti.day<<endl;
cout<<"Hour: "<<ti.hour<<endl;
cout<<"Minute: "<<ti.minute<<endl;
cout<<"Second: "<<ti.second<<endl;
return 0;
}
检查出现C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'year' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'month' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'day' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'hour' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'minute' used without having been initialized
C:\Program Files\VC++\MyProjects\p63\31.cpp(16) : warning C4700: local variable 'second' used without having been initialized
但是可以执行;
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct Time{
int year;
int month;
int day;
int hour;
int minute;
int second;
};
int main(){
int year,month,day,hour,minute,second;
cout<<"please enter the year,month,day,hour,minute,second"<<endl;
cin>>"year: ">>"month: ">>"day: ">>"hour: ">>"minute: ">>"second: ">>endl;
Time ti={year,month,day,hour,minute,second};
cout<<"Year: "<<ti.year<<endl;
cout<<"Month: "<<ti.month<<endl;
cout<<"Day: "<<ti.day<<endl;
cout<<"Hour: "<<ti.hour<<endl;
cout<<"Minute: "<<ti.minute<<endl;
cout<<"Second: "<<ti.second<<endl;
return 0;
}
这个检查出现一个错误
error C2679: binary '>>' : no operator defined which takes a right-hand operand of type '' (or there is no acceptable conversion)
求解释!!