void printAst(int x)
{
for(int i = 0; i < x; i++)
{
cout << "*";
}
cout << " (" << x << ")" << endl;
}
void printHisto(int histo[])
{
//cout.precision(3);
int count = 0;
for(double i = -3.00; i < 3.00; i += 0.25)
{
cout << setprecision(3) << i << " to " << i + 0.25 << ": " << printAst(histo[count]) << endl;
// cout << setw(3) << setfill('0') << i << " to " << i + 0.25 << ": " << histo[count] << endl;
count ++;
}
}
我希望我的输出格式化为这样,所以我使用setprecision(3),它也不起作用。'std :: operator <<'operator <<'不匹配'std :: operator <<
-3.00到-2.75:(0)
-2.75 -2.50到:*(1)
-2.50 -2.25:*(1)
-2.25 -2.00:* ( 6)
-2.00 -1.75到: ** * **(12)
所以代替它被格式化这样
-3〜-2.75:3
-2.75至-2.5:4
-2.5 -2.25:5
-2.25至-2:0
-2至-1.75:0
的主要问题不过,当我尝试将printAst调用到histo [count]时。这是什么导致这个错误。 PrintAst用于打印星号,histo [count]提供要打印的星号数量。
COUT < < setprecision(3)< <我< < “到” < < 1 + 0.25 < < “:” < < printAst(HISTO [COUNT])< < ENDL;
这与标题有什么关系? –
'<< printAst(histo [count])'< - 这是错误的。这个函数返回void。你不能流无效。 – Borgleader