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