if else语句中的c ++错误,我的语法有什么问题?

时间:2013-10-28 03:39:47

标签: c++

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

ass4.cpp:46:错误:无法将'std :: string'转换为'int'作为回报 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          }

2 个答案:

答案 0 :(得分:2)

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

语法无效,更新为

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

还抱怨将stringint类型进行比较,是type_s字符串类型吗?

答案 1 :(得分:0)

  1. 您的函数是否定义为返回intreverse会返回std::string吗?那不行。改变其中一个。

  2. if else不是合法语法。根据您的情况,您似乎应切换到else if