我不明白为什么我在尝试编译时遇到这些错误。我从来没有遇到'预期的_之前_令牌'的错误,但我认为它们很常见(如果没有足够的启发我的话)。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