C++ 需要帮助格式化输出C++;
我的显示除法表的功能正在运行,但我希望格式化输出,允许小数点前有任意数量的字符,但将小数点后的位数限制为2。这是我正在使用的代码。一旦我添加了行C++ 需要帮助格式化输出C++;,c++,C++,我的显示除法表的功能正在运行,但我希望格式化输出,允许小数点前有任意数量的字符,但将小数点后的位数限制为2。这是我正在使用的代码。一旦我添加了行cout.setf(std::ios::fixed,std::ios::floatfield)我的数据似乎格式正确,但我在实际数字的前面追加了额外的数字。 因此,程序不打印1.00,而是打印40981.00,并对所有结果执行此操作。(前面的数字变为4102x.xx)x是所需的输出 void print_div_values(mult_div_values
cout.setf(std::ios::fixed,std::ios::floatfield)
我的数据似乎格式正确,但我在实际数字的前面追加了额外的数字。
因此,程序不打印1.00
,而是打印40981.00
,并对所有结果执行此操作。(前面的数字变为4102x.xx
)x是所需的输出
void print_div_values(mult_div_values ** table, float x, float y){
cout << endl << "Here is the division table: " << endl;
for (int i = 1; i <= y; i++)
{
cout << endl;
for (int j = 1; j <= x; j++)
{
cout << std::setw(5) << cout.setf(std::ios::fixed, std::ios::floatfield) << std::setprecision(2) << table[i][j].div;
}
cout << endl;
}
无效打印分区值(多分区值**表,浮点x,浮点y){
coutstd::ostream::setf
返回旧标志,然后由cout
将其格式化为整数。使用
cout.setf(std::ios::fixed, std::ios::floatfield);
cout << std::setw(5) << std::setprecision(2) << table[i][j].div;
cout.setf(std::ios::fixed,std::ios::floatfield);
coutstd::ostream::setf
返回旧标志,然后由cout
将其格式化为整数。使用
cout.setf(std::ios::fixed, std::ios::floatfield);
cout << std::setw(5) << std::setprecision(2) << table[i][j].div;
cout.setf(std::ios::fixed,std::ios::floatfield);
复制粘贴做不到,为什么浪费空间?是的,抱歉下次会这样做。复制粘贴做不到,为什么浪费空间?是的,抱歉下次会这样做。谢谢你的帮助。所以我的问题是顺序和试图在一行中做太多的事情?有点。如果你想在一行中做,你可以编写cout谢谢你的帮助。所以我的专业版问题是顺序,试图在一行中做太多的事情?有点。如果你想在一行中做,你可以写cout