C++ 我使用std::fixed缺少什么?

C++ 我使用std::fixed缺少什么?,c++,C++,我正在编写一个程序来模拟plinko板,在这个程序中我有一个函数,可以输出分配给每个插槽的钱。我试图使用std::fixed和std::setprecision输出每个值,每个值在小数点后有两个零,但是每个值的输出都好像我根本没有使用fixed一样。我错过了什么?这是我的密码: #include <iostream> #include <iomanip> using namespace std; void ChipsAllSlots(int numChips) {

我正在编写一个程序来模拟plinko板,在这个程序中我有一个函数,可以输出分配给每个插槽的钱。我试图使用std::fixed和std::setprecision输出每个值,每个值在小数点后有两个零,但是每个值的输出都好像我根本没有使用fixed一样。我错过了什么?这是我的密码:

#include <iostream>
#include <iomanip>

using namespace std;

void ChipsAllSlots(int numChips) {
    const int NUM_SLOTS = 9;
    const int slotWinnings[NUM_SLOTS] = {100, 500, 1000, 0, 10000, 0, 1000, 500, 100};

    for (int i = 0; i < numChips; ++i) {
        cout << fixed << setprecision(2) << slotWinnings[i] << endl;
    }
}

int main() {
    ChipsAllSlots(9);
    return 0;
}
#包括
#包括
使用名称空间std;
空芯片插槽(整数芯片){
const int NUM_SLOTS=9;
const int slotwings[NUM_SLOTS]={1005001000,010000,010000500100};
对于(int i=0;icout
std::fixed
std::setprecision
仅影响浮点数的输出。您输出整数,因此这些操纵器没有任何效果。如果您在插入流之前转换为浮点,或者首先使用浮点数组,那么您将看到正在使用的
.00
issing.

slotwings[]
类型为
int
固定
并且在输出
int
值时不考虑
setprecision()
。如果需要小数点和两个0位,只需打印
.00即可“我知道我错过了像这样愚蠢的事情。非常感谢!”杰克,如果它有帮助,请考虑作为一个答案。