2011-05-01 153 views
1

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

回答

3

您在cout << "Out of Bounds!!!"行到底有没有;

您有if (i=0; i < 2; i++);那应该是for (i=0;...

您有cin << side;那应该是cin >> side

你已经定义了你的函数体里面的main();他们应该住在外面。

+0

嘿到底需要一个;,我读得太快。我甚至没有看到'if' =>'for'。 – 2011-05-01 16:26:59

0

您正在定义main()定义中的函数printStar()等。将这些函数移到main()的右括号之外。

0

int main()方法的结束}需要去void printStart(int a)之前。

此外,您在cout << "Out of Bound!!!"