c++ - 如果 stat 语句不起作用

标签 c++ xcode

我试图根据给定的用户输入使 if 语句为真或假,但是当我将条件放入其中时,它表示此二进制表达式的操作数无效 ('string'(又名'basic_string')和'int')

这是我的代码

#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;
}

最佳答案

  if (userinput == 2);
                    ^^^

同样,在 if 之后到处都有分号,我认为这不是您想要的。

关于c++ - 如果 stat 语句不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12439017/

相关文章:

ios - 如何发送不显示 Composer 的电子邮件+附件

c++ - 具有递归模板参数包函数是否为每次迭代创建特定函数?

c++ - Boost 异步定时器仍然阻塞主线程

xcode - 检查专注于 XCUITest 的 UITextField

objective-c - 在 Xcode 4.2 中找不到框架 header ,但应用程序运行正常

iphone - dealloc 方法在基于 ios5 的项目中默认不存在

cocoa - 带有核心数据的基于文档的应用程序与普通核心数据应用程序?

c++ - Visual C++ 链接器无法解析 FFmpeg 的外部符号

c++ - 循环遍历struct元素

C++ 函数与带有整数参数的模板?