无法理解 if 命令

cannot understand the if command

本文关键字:if 命令      更新时间:2023-10-16

我正在尝试编写一个程序,当我键入load时,该程序会在控制台中显示一条自定义消息。但我似乎无法让它工作。:/

#include "stdafx.h"
#include "iostream"
#include "string"
using namespace std;
int main()
{
int commands();
string text;
cout << "Write your registered e-mail to continue...n";
cin >> text;
string input;
cout << "n";
cout << "Welcome " << text << endl;
cout << "n";
cout << "www.steamcommunity.com/id/thetraderdazz> ";
cin >> input;
if (input = load);
cout << "loading...";
system("pause");
return 0;
}

它还给了我以下错误:

标识符"负载"未定义。

if (input = load);

这条线有三个错误。首先是您使用了赋值运算符=而不是比较运算符==。前者分配,后者比较。

第二个错误是你在括号后面放了一个分号,表示一个空的正文。编译器应该已就此发出警告。

最后,没有变量load。你的意思是与字符串文字"load"进行比较.

修复到

if (input == "load")
cout << "loading...n";

您可能打算执行以下操作

if (input == "load") {
cout << "loading...";
}