我不明白爲什麼我在嘗試編譯時遇到這些錯誤。我從來沒有遇到'預期的_之前_令牌'的錯誤,但我認爲它們很常見(如果沒有足夠的啓發我的話)。C++編譯錯誤
pe4.cpp: In function
'int main()'
:
pe4.cpp:18: error: expected')'
before';'
token
pe4.cpp:18: error: expected';'
before')'
token
pe4.cpp:45: error: a function-definition is not allowed here before'{'
token
pe4.cpp:51: error: a function-definition is not allowed here before'{'
token
pe4.cpp:57: error: a function-definition is not allowed here before'{'
token
#include <iostream>
using namespace std;
void printStar(int);
void printSpace(int);
void printNewLine();
int main()
{
int side, i, j;
if (i=0; i < 2; i++)
{
cout << "Enter side: " << endl;
cin << side;
if (side < 3 || side > 20)
{
cout << "Out of Bounds!!!"
return 0;
}
printStar(side);
printNewLine();
{
printStar(1);
printSpace(side-2);
printStar(1);
printNewLine();
}
printStar(side);
printNewLine();
}
void printStar(int a)
{
for (int j = 0; j < a; j++)
cout << "*";
}
void printSpace(int a)
{
for (int j = 0; j < a; j++)
cout << " ";
}
void printNewLine()
{
cout << endl;
}
}
嘿到底需要一個
;
,我讀得太快。我甚至沒有看到'if' =>'for'。 – 2011-05-01 16:26:59