gpt4 book ai didi

c++ - 左边的点精度

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:27 26 4
gpt4 key购买 nike

我想写的是这样的

file << someFunction(5) << hex << 3;

并获得这样的输出 00003 而不是 3(300 将是 00300,等等)

注意:- 抱歉,如果之前有人问过这个问题,我不知道要搜索什么词才能得到这个

编辑:- 我的意思是左边的零,我包括了十六进制部分只是为了清楚我希望它与这种格式兼容

最佳答案

我相信这就是你的意思。

#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::setw(5) << std::setfill('0') << 3 << '\n';
return 0;
}

输出

00003

链接 setw , setfill .

编辑:另请参阅 std::internal at this question .

关于c++ - 左边的点精度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16463525/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com