我正尝试在C++20中使用#include < format >创建一个表,但是我不知道如何同时创建17位的居中对齐和2位小数的精度。我知道17居中对齐的宽度很简单: cout<
这是我的代码片段:
for (size_t k{};k<length;++k)
{
cout << "Enter the product number:\n";
cin >> value;
product.push_back(value);
cout << "Enter the quantity:\n";
cin >> value;
quantity.push_back(value);
cout << "Enter the unit price($):\n";
cin >> value;
price.push_back(value);
}
cout << "Product Quantity Perunit($) Cost($)" << endl;
for (int i = 0; i < product.size(); i++)
{
cout << format("{:<}{:^15}{:^7}{:^17.2}\n",product[i],
quantity[i],price[i],(quantity[i]*price[i]));
}
我试着做{:^17.2},但什么也没做(请看图片)。请多多指教。
发布于 2021-07-19 05:11:03
尝试包含f
说明符(用于浮点数):{:^17.2f}
https://stackoverflow.com/questions/68433089
复制相似问题