如果 else 语句中的 C++ 错误,我的语法有什么问题

c++ error in if else statement, what is wrong with my syntax?

本文关键字:语法 我的 什么 问题 错误 语句 else C++ 如果      更新时间:2023-10-16

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

ass4.cpp:46:错误:无法将"std::string"转换为"int"ass4.cpp:49:错误:预期"("在"else"之前

 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          }
if else((type_f == 1) && (type_s == 2))
^^^^^^^

语法无效,请更新为

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

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

  1. 您的函数是否定义为返回intreverse返回std::string吗? 这是行不通的。 更改一个或另一个。

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