[英]C++ Compile Error
當我嘗試編譯時,我無法弄清楚為什么會出現這些錯誤。 我從來沒有遇到過'expected _ before _ token'錯誤,但我相信它們很常見(如果不能隨意啟發我)。
pe4.cpp:在 function
'int main()'
:
pe4.cpp:18: 錯誤:在';'
之前預期')'
' 令牌
pe4.cpp:18: 錯誤: 預期';'
在')'
標記之前
pe4.cpp:45:錯誤:在'{'
標記之前不允許函數定義
pe4.cpp:51:錯誤:在'{'
標記之前不允許函數定義
pe4.cpp:57:錯誤:在'{'
標記之前不允許函數定義
#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()
中定義了 function 主體; 他們應該住在外面。
您正在 main() 定義中定義函數 printStar() 等。 將這些函數移到 main() 的右括號之外。
int main()
方法的結束}
需要在void printStart(int a)
之前 go 。
另外,你需要一個;
在cout << "Out of Bound!!!"
結尾處
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.