在C++中使用cout对齐Integer
Align Integer using cout in C++
我需要C++使用cout打印:
Header
1
2
3
4
5
10
11
12
而不是
Header
1
2
3
4
5
10
11
12
我应该如何使用cout格式化这个?
使用IO操纵器setw
#include <iostream>
#include <iomanip>
int main()
{
std::cout << "Headern";
for(int i=1; i<13; ++i)
std::cout << std::setw(6) << i << 'n';
}
相关文章:
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- 如何创建一个QTableWidgetItem,用长文本右对齐,左边有省略号
- 我可以检测和更改 gcc/g++ 中结构的当前数据对齐设置吗?
- 64位机器上的C++内存对齐
- 为什么我可以将变量存储在不是其最小对齐方式的倍数的地址?
- 使 std::vector 分配对齐内存的现代方法
- C++ cout 将双精度对齐到精度 2 并正确对齐
- 在 64 位边界上对齐C++结构数组?
- 使用 g++7 构建的代码在访问未对齐的内存时崩溃
- 在 capnp FlatArrayMessageReader 的对齐内存缓冲区中接收 zmq 消息
- 是否值得对齐变量?
- 初始化派生结构的基部分/意外打包派生结构字段以对齐基结构的间隙
- 对齐和对齐的实际用例C++关键字
- C++ cout 列表,其中小数点使用 setw(x) 对齐,而不是put_money
- C++ cout 对齐输出数字
- cout 不能一致地打印字符串和变量值,导致输出未对齐
- 如何使用 cout 将文本右对齐
- cout << setw 与 åäö 正确对齐
- 将输出文本与 cout 对齐到右侧
- 在C++中使用cout对齐Integer