2013-10-28 47 views
-1

我的if else語句中出現以下錯誤。語法有什麼問題?if語句中的C++錯誤,我的語法有什麼問題?

ass4.cpp:46:錯誤:無法轉換 '的std :: string' 到 '廉政' 的回報 ass4.cpp:49:錯誤:預期 '(' 前 '其他'

41 if ((type_f == 1) && (type_s == 1)) 
42   { 
43   cout << "11" << endl; 
44 
45   // 1 1 = iterative, reverse 
46   return reverse(str_input); 
47   } 
48 
49 if else((type_f == 1) && (type_s == 2)) 
50   { 
51   cout << "12" << endl; 
52 
53   return palin_l(str_input); 
54   } 
+0

我們在這裏需要更多的上下文。你能發佈一個完整的,自包含的例子,讓我們得到錯誤嗎? – templatetypedef

+1

好吧,顯然,你要返回一個字符串而不是int。 – chris

+2

,你可能的意思是'else if'而不是'if else' – rici

回答

0
  1. 定義爲返回int的功能?是否reverse返回std::string?這是行不通的。改變一個或另一個。

  2. if else是不合法的語法。從你那裏有什麼,它看起來你應該切換到else if

2
if else((type_f == 1) && (type_s == 2)) 
^^^^^^^ 

是無效的語法,更新

else if ((type_f == 1) && (type_s == 2)) 

此外,它抱怨比較stringint類型,是type_s string類型?

+0

type_s是一個int。 – guesswho

+0

錯誤信息可能來自無效的語法,你是否更新了'if else'到'else if'?它修復了什麼嗎? – billz

+0

這並不是抱怨比較;這是關於46號線倒退的情況。 – ChiefTwoPencils