如何将 x 打印为 0x,其中 x 是整数 C++
How to print x as 0x where x is an integer C++
我想打印出 minutes:second.miliseconds 这样的时间。
想想那个时间是4分2秒65毫秒
而不是写成 4:2.65 我想写成 4:02.065
我该怎么做?
如果您使用 iostream 或 stringstream:
#include <iostream>
#include <iomanip>
[...]
int val = 1;
std::cout << std::setw(2) << std::setfill('0') << val << std::endl;
[...]
std::setw 设置后续元素的宽度。
std::setfill 设置填充空 space.
的字符
你会用 iomanip
#include <iomanip>
#include <iostream>
//intermediate code goes here
std::cout << minutes << ":" << std::setfill('0') << std::setw(2) << seconds << "." << std::setw(3) << milliseconds << std::endl;
我想打印出 minutes:second.miliseconds 这样的时间。
想想那个时间是4分2秒65毫秒
而不是写成 4:2.65 我想写成 4:02.065
我该怎么做?
如果您使用 iostream 或 stringstream:
#include <iostream>
#include <iomanip>
[...]
int val = 1;
std::cout << std::setw(2) << std::setfill('0') << val << std::endl;
[...]
std::setw 设置后续元素的宽度。
std::setfill 设置填充空 space.
的字符你会用 iomanip
#include <iomanip>
#include <iostream>
//intermediate code goes here
std::cout << minutes << ":" << std::setfill('0') << std::setw(2) << seconds << "." << std::setw(3) << milliseconds << std::endl;