注意事项有
-
类型 占用存储空间 表数范围 byte 1字节 -2^7 ~ 2^7-1(-128~127) short 2字节 -2^15 ~ 2^15-1(-32768~32767) int 4字节 -2^31 ~ 2^31-1 (-2147483648~2147483647) 约21亿 long 4字节 -2^31 ~ 2^31-1 long long 8字节 -2^63 ~ 2^63-1 -
c++ 输出前补0,
头文件:<iomanip>
函数:setw(int n)
函数:setfill(char c)(不调用该函数时默认用空格进行占位)
cout<<setw(8)<<setfill('0')<<123<<endl;
输出:00000123
-
#include<iostream> #include<iomanip> using namespace std; int main() { long long time; cin>>time; time=time/1000; int seconds=0; int minute=0; int hours=0; seconds=time%60; time=time/60; minute=time%60; time=time/60; hours=time%24; cout<<setw(2)<<setfill('0')<<hours<<":"; cout<<setw(2)<<setfill('0')<<minute<<":"; cout<<setw(2)<<setfill('0')<<seconds<<endl; return 0; }