2015-02-08 867 views
-1

尝试创建新的void函数时出现Expected ‘)’ before ‘;’ token 错误。expected')'before';'令牌函数

下面是摘录:

我不知道这个错误应该如何解决。我也有望在)令牌之前使用加密技术。

using namespace std; 

void ascii_to_bin() 
{ 
    string test; 
    int ascii; 
    int asciibinary; 
    unsigned int i = 0; 
    cout << "Enter a string: "; 
    getline (cin,test); 
    for (i = 0; i < test.size(); i++) 
    { 
     ascii = int(test[i]); 
     bitset<8> asciibinary (ascii); 
     cout << asciibinary << endl; 
    } 
} 

void calculate_binary(string binarystring; int stringlen) 
{ 
    int num_characters; 
    num_characters = (stringlen)/8; 
    int binary[8]; 
    int asciinum; 
    char asciichar; 
    int j = 0; 
    i = 0; 

    for (int y = 0; y < num_characters; y++) 
    { 
     for (i = 0; i < 8; i++) 
     { 

      binary[i] = (int)binarystring[j]-48; 
      j++; 
     } 
     int power[8]; 
     int counter = 7; 
     for (int c = 0; c < 8; c++) 
     { 
      power[c] = counter; 
      counter --; 
     } 

     for(int z = 0; z < 8; z++) 
     { 
      double a = binary[z]; 
      double b = power[z]; 

      asciinum += a*pow(2,b); 
      cout << asciinum << endl; 
     } 
     asciichar = asciinum;`` 

     cout << asciichar << endl; 
     asciinum = 0; 
    } 
} 
+4

您的错误消息是否包含行号?你检查过那个行号吗? – Tom 2015-02-08 21:51:46

+3

事实上,在此行末尾有2个刻度线可能没有帮助: asciichar = asciinum;'' – 2015-02-08 21:57:28

+3

请告诉我们正在标记的行号以及该行号的语句。 – jww 2015-02-08 21:59:08

回答

2

该错误是因为该行的:

void calculate_binary(string binarystring; int stringlen) 

分号应该是一个逗号:

void calculate_binary(string binarystring, int stringlen) 

分号用于分隔语句,而逗号用于将多个参数分隔到一个函数中。