我无法弄清楚为什么在尝试编译时会出现这些错误。我从未遇到过“expected _ before _ token”错误,但我相信它们很常见(如果有问题请随时启发我)。
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;
}
}
最佳答案
你没有;
在 cout << "Out of Bounds!!!"
的末尾行。
你有 if (i=0; i < 2; i++)
;那应该是 for (i=0;...
.
你有 cin << side
;那应该是 cin >> side
.
您已经在内部定义了您的函数体 main()
;他们应该住在外面。
关于C++ 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5849639/