我对C++很陌生。这是我目前正在处理的,我想你可以猜出我试图应用到程序中的逻辑,这样它才能工作。我需要用户提供一个要执行的算法,如果它是一个特定的数字相加在一起。以下是代码:
#include <iostream>
#include <string>
using namespace std;
int main()
{
int x;
int v;
int sum;
string input;
cout << "Choose arithmetic: addition or subtraction? " << endl;
cin >> input;
if(input=='Addition'||input=='addition')
{
int first;
int second;
int sum = first+second;
cout << "Enter the first number: " << endl;
cout << "Enter the second number: " << endl;
cout << "The sum of these numbers is: " << sum << endl;
}
return 0;
}
编译器给出了以下错误:13错误:“输入== 1953066862”中的“operator==”不匹配
提前谢谢你!
发布于 2013-08-28 18:04:01
C++中的文字字符串使用双引号,而不是单引号。也就是说,"Addition"
而不是'Addition'
。
单引号字符串称为“多字符常量”,它是有效的,但绝对不是您想要的。
发布于 2013-08-28 18:04:09
在C/C++中,字符串应该是"“而不是”“。应该是"Addition"
。
发布于 2013-08-28 18:09:24
在下面的行中尝试使用双引号(")而不是单引号('):
if(input=='Addition'||input=='addition')
https://stackoverflow.com/questions/18501181
复制相似问题