我在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 }
答案 0 :(得分:2)
if else((type_f == 1) && (type_s == 2))
^^^^^^^
语法无效,更新为
else if ((type_f == 1) && (type_s == 2))
还抱怨将string
与int
类型进行比较,是type_s
字符串类型吗?
答案 1 :(得分:0)
您的函数是否定义为返回int
? reverse
会返回std::string
吗?那不行。改变其中一个。
if else
不是合法语法。根据您的情况,您似乎应切换到else if
。