-1

我在 if else 语句中收到以下错误。语法有什么问题?

ass4.cpp:46: 错误: 无法将 'std::string' 转换为 'int' 以返回 ass4.cpp:49: 错误: 预期 '(' 在 'else' 之前</p>

 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          }
4

2 回答 2

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

语法无效,更新为

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

它还抱怨与string类型进行比较int,是type_s字符串类型吗?

于 2013-10-28T03:42:50.327 回答
0
  1. 您的函数是否定义为 return int?是否reverse返回一个std::string?那是行不通的。改变一个或另一个。

  2. if else不是合法的语法。从您那里的情况来看,您应该切换到else if.

于 2013-10-28T03:42:20.917 回答