定义一个表示时间的结构体,可以精确的表示年、月、日、小时、分、秒,提示用户输入年、月、日、小时、分、秒的值,然后完整的显示出来。
时间: 2023-09-24 08:06:57 浏览: 63
好的,以下是一个C++的示例代码:
```cpp
#include <iostream>
using namespace std;
struct Time {
int year;
int month;
int day;
int hour;
int minute;
int second;
};
int main() {
Time t;
cout << "请输入年份:";
cin >> t.year;
cout << "请输入月份:";
cin >> t.month;
cout << "请输入日期:";
cin >> t.day;
cout << "请输入小时数:";
cin >> t.hour;
cout << "请输入分钟数:";
cin >> t.minute;
cout << "请输入秒数:";
cin >> t.second;
cout << "您输入的时间是:" << t.year << "年" << t.month << "月" << t.day << "日 " << t.hour << "时" << t.minute << "分" << t.second << "秒" << endl;
return 0;
}
```
运行结果如下:
```
请输入年份:2022
请输入月份:6
请输入日期:1
请输入小时数:12
请输入分钟数:30
请输入秒数:15
您输入的时间是:2022年6月1日 12时30分15秒
```