C++ 将整数更改为货币格式而不更改cout函数

C++ 将整数更改为货币格式而不更改cout函数,c++,C++,我有一个整数carCost,我需要以货币格式显示,即3700.00 然而,我们不应该改变它打印的代码 TODO: Make the quote lines below print to look like money // Example 3.45234 should be --> 3.45 // Think about iomanip // --------------------------------------- // Put some code in here // ---

我有一个整数carCost,我需要以货币格式显示,即3700.00 然而,我们不应该改变它打印的代码

TODO: Make the quote lines below print to look like money



// Example 3.45234 should be --> 3.45
// Think about iomanip
// ---------------------------------------
// Put some code in here
// ---------------------------------------
static_cast<double>(carCost);
static_cast<double>(upgradeCost);



// ---------------------------------------
// ============================================================
// Don't mess with these lines ================================
// ============================================================
std::cout << "[" << quoteNumber++ << "] "; // Don't touch me
std::cout << " Car($" << carCost << ")"; // Don't touch me
std::cout << " E(" << engineLevel << ")"; // Don't touch me
std::cout << " T(" << tireLevel << ")"; // Don't touch me
std::cout << " R(" << rimLevel << ")"; // Don't touch me
std::cout << " P(" << paintLevel << ")"; // Don't touch me
std::cout << " M(" << mufflerLevel << ")"; // Don't touch me
// Don't touch the following line -- HOWEVER, you should put
// something in the space ABOVE to make this line print like money
std::cout << " Upgrades($" << upgradeCost << ")" << std::endl; // Don't touch me
// ============================================================
TODO:将下面的报价行打印出来,使其看起来像钱一样
//示例3.45234应为-->3.45
//想想iomanip
// ---------------------------------------
//在这里输入一些代码
// ---------------------------------------
静态成本;
静态成本(升级成本);
// ---------------------------------------
// ============================================================
//不要弄乱这些线路================================
// ============================================================
std::cout将
#include
添加到您的
#include
中,您可以使用


std::难道你不能更改流设置吗?我不知道,但代码明确说明不涉及我和“不要碰下面这一行——不过,你应该在上面的空白处放些东西,让这一行像钞票一样印出来。”。所以carCost的值从3700变为3700.00,然后在std::cout FYI行中,值
3700
就是值
3700.00
,只是格式不同而已。“更改值”不会影响输出格式。请告诉老师有意义的作业tbh。但是答案是:
std::cout就是这样谢谢你。我认为“fixed”和“setprecision”必须用cout应用于单个变量。我不知道你可以像一张笼统的声明一样使用。谢谢大家