2017-08-26 65 views
-5

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

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

这也给了我下面的错误:

identifier "load" is undefined.

+6

你似乎有对C++的不少误解。你应该退后一步,系统地从一本好书中学习语言。 –

+0

同意上面的评论。这里有一些你的特定问题的帮助https://stackoverflow.com/questions/6222583/how-to-compare-strings – ivo

+0

我同意上面的所有意见,但首先,你应该使用strcmp函数而不是'=' (它的作用,我认为你的意思是'=='),你必须使'load'成为一个字符串,所以:''load''。 –

回答

2
if (input = load); 

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

第二个错误是您在括号后面放置了分号,表示为空体。你的编译器应该给你一个警告。

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

修复到

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

你可能预期下

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