19、时间转换
📅 2026/7/6 14:51:25
👁️ 阅读次数
📝 编程学习
#include <iostream> #include <iomanip> // setw setfill 格式化补0需要这个头文件 using namespace std; int main() { int n; cout << "请输入总秒数:"; cin >> n; int hour = n / 3600; // 小时 int minute = n % 3600 / 60; // 分钟 int sec = n % 60; // 秒 // setw(2)占两位,setfill('0')不足补0 cout << setfill('0') << setw(2) << hour << ":" << setw(2) << minute << ":" << setw(2) << sec << endl; return 0; }
编程学习
技术分享
实战经验