C++ 如果stat语句不工作
我试图根据用户的输入使if语句为true或false,但当我将条件放入其中时,表示这是二进制表达式的无效操作数 ('string'(又名'basic_string')和'int') 这是我的密码C++ 如果stat语句不工作,c++,xcode,C++,Xcode,我试图根据用户的输入使if语句为true或false,但当我将条件放入其中时,表示这是二进制表达式的无效操作数 ('string'(又名'basic_string')和'int') 这是我的密码 #include <iostream> #include <string> using namespace std; int main() { cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl;
cout << " X X" << endl;
cout << " X MENU X" << endl;
cout << " X X" << endl;
cout << " X Press 1 to Play The Word Game. X" << endl;
cout << " X X" << endl;
cout << " X Press 2 Too See a calculator. X" << endl;
cout << " X X" << endl;
cout << " X X" << endl;
cout << " XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" << endl
<< endl;
string userinput;
cin >> userinput;
if (userinput == 1);{
while (1<2)
{
cout << "Enter the Word." << endl;
string UserInput;
cin >> UserInput;
cout << endl << UserInput << " is is not the right word but keep on trying" << endl << endl;
cout << "Press Enter to Continue.";
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
}
if (userinput == 2);
{ int z;
int x;
int sum;
cout << " welcome to the calculator" << endl << endl;
cin.clear();
cin.ignore(255, '\n');
cin.get();
cout << "enter your first number";
cin >> z; cout << endl << endl;
cout << "enter your second number" << endl;
cin >> x; cout << endl << endl;
sum = z + x;
cout << sum;
}
cin.clear();
cin.ignore(255, '\n');
cin.get();
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
库特
同样,在if
后面到处都有分号,我认为这不是您想要的
同样,在if
后面到处都有分号,我认为这不是您想要的。请删除此处的分号:
if(userinput==1);{
if(userinput==2);
而且不能将字符串与int进行比较
string userinput;
cin >> userinput;
if (userinput == 1);{
所以试试看
int userInput ;
如果您坚持使用字符串,请查看:
删除此处的分号:
if(userinput==1);{
if(userinput==2);
而且不能将字符串与int进行比较
string userinput;
cin >> userinput;
if (userinput == 1);{
所以试试看
int userInput ;
如果您坚持使用字符串,请查看:
这没有多大帮助,但仍然是一样的thing@user1610489看看我的answer@user1610489是的,如果您不想比较字符串,请将其更改为int
。但您的意图是使用integer。这没有多大帮助,它仍然表示相同thing@user1610489看看我的answer@user1610489是的,把它改成 int
如果你不能使用==如果你想比较字符串。但是你的意图是使用整数。非常感谢这让我很沮丧很长时间了time@user1610489如果这有助于你接受答案,也意味着人们可能会回答你的问题。非常感谢这让我很沮丧很长时间了time@user1610489如果这有助于你接受答案,也意味着人们可能会回答你的问题。