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)도 사용됩니다. -2.75에'operator <<'for 'std :: operator <<
-3.00 (0)
-2.75 -2.50로 * (1) -2.25 -2.50에
: * (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
주요 문제점 : 0
-2 -1.75 행 그러나, 나는 printAst를 histo [count]에 호출하려고 할 때이다. 이것은이 오류의 원인입니다. PrintAst는 별표를 인쇄하는 데 사용되고, histo [count]는 인쇄 할 별표의 양을 제공합니다.
COUT < < setprecision (3) < < < < I "를"난 < + < 0.25 < < ":"< < printAst (히스 [카운트]) < < ENDL;
제목과 어떤 관련이 있습니까? –
'<< printAst (histo [count])'<- 이것은 잘못되었습니다. 이 함수는 void를 반환합니다. 스트리밍 할 수는 없습니다. – Borgleader