使用cin时,字符串上的右操作数错误
Right-hand operand error on string when using cin
我正在尝试制作一个基本的计算器,它将使用do-while
循环并提示用户是否希望从头重新运行计算器的答案。
对于yes
或no
的字符串字面值答案,我在cin
上遇到以下错误:
<Error C2679 binary '>>': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)>
我该如何解决这个问题?
int main()
{
double x;
double z;
char o;
string a;
char Y, y;
do
{
cout << "Please input a value for x: " << endl;
cin >> x;
cout << "Please input a value for z: " << endl;
cin >> z;
cout << "Please pick an operation to do: * / + -" << endl;
cin >> o;
switch (o) {
case '+':
cout << x << " + " << z << " = " << x + z << endl;
break;
case '-':
cout << x << " - " << z << " = " << x - z << endl;
break;
case '*':
cout << x << " * " << z << " = " << x*z << endl;
break;
case '/':
if (z != 0)
{
x / z;
cout << x << " / " << z << " = " << x / z << endl;
}
else
{
cout << "Can not divide by zero! Nice try, Pedersen!" << endl;
}
break;
default:
cout << "/n/n/tThank you for using my calculator!" << endl << endl;
}
system("cls");
cout << "/n/n/tDid you want to run the calculator again?" << endl << endl;
cin >> a;
}while (a == "Yes" || a == "yes");
system("pause");
return 0;
您的问题的解决方案可以找到@来源:错误C2678:二进制'>>'std::istream'(或者没有可接受的转换)
你需要#include <string>
相关文章:
- 错误 C2679:二进制"<<":未找到采用类型 'std::string_view' 的右侧操作数的运算符(或者没有可接受的转换)
- 错误:类型"double()"和"double()"的操作数无效到二进制&quo
- 错误:二进制'operator*' 'float'和'float[0]'类型的操作数无效
- 错误 C2679 二进制"<<":未找到采用类型为 'T' 的右侧操作数的运算符
- 错误:'operator>'不匹配(操作数类型为 'Student' 和 'Student'
- 如何摆脱逗号运算符的这个错误右操作数没有效果( wunsued 值)?
- c++ 错误:二进制"运算符+"类型"矩阵*"和"矩阵*"的操作数无效
- 使用堆栈编译错误的 C++ 反向行没有运算符匹配操作数
- 当我尝试构建此程序时,出现此错误:需要左键作为赋值的左操作数
- 错误:二进制">>":未找到采用类型为"const char [1] 的右操作数的运算符
- C++ 重载:[错误] 与'operator='不匹配(操作数类型为 'String' 和"字符串")
- 错误 C2679:二进制'<<':找不到采用类型 'overloaded-function' 的右侧操作数的运算符(或者没有可接受的转换)
- 我收到一个错误无效的操作数,类型为 const char [42] 和二进制"运算符+"的双倍数
- C++ 运算符不匹配操作数错误
- c++的cout操作数错误,类型错误
- 使用cin时,字符串上的右操作数错误
- OpenCV无效操作数错误
- 需要lvalue作为增量操作数错误
- C++无效操作数错误
- c++模板类冒泡排序操作数错误