带括号的预期Unqualified-id错误

时间:2014-09-21 22:56:44

标签: c++ error-handling syntax-error

这是我的代码:

16 using namespace std;
17
18 void printInOrder(string s1, string s2, string s3);
19
20 int main()
21 {
22        string  w1, w2, w3;             // input values                     
23
24        cin >> w1 >> w2 >> w3;          // read in three values             
25        printInOrder(w1, w2, w3);       // function does not return anything                                                                           
26
27        return 0;
28
29 }
30 //                                                                          
31 // printInOrder() prints out the three words in alpha order                 
32 //                with spaces between them, no return value                 
33 //                                                                          
34 void printInOrder(string x, string y, string z)
35 {
36        // your code here                                                   
37        // your function does NOT use return                                
38        // Instead, it sends values to cout                                 
39        // Just print the 3 strings as described in the assignment          
40        // with no extra stuff.                                             
41
42        if (x<24 && y<20 && z<24)
43                cout << x, y, z << endl;
44
45                return;
46
47 }

我一直收到错误:

mid3.cpp:39:1: error: expected unqualified-id before ‘{’ token

无法弄清楚什么是错的!!

谢谢!

1 个答案:

答案 0 :(得分:1)

第42行的

,你应该将每个条件放在()中,我不知道你为什么要将字符串与int进行比较! 在第43行,你应该写:

cout << x << y << z << endl;