-5

I'm trying to write a program, which shows a custom message in the console when I type load. But I can't seem to get it to work. :/

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

It also gives me the following error:

identifier "load" is undefined.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59
  • 6
    You seem to have quite a few misunderstandings about C++. You should take a step back and systematically learn the language from a good book. – Baum mit Augen Aug 26 '17 at 14:27
  • Agree with comment above. Here's some help with your particular problem https://stackoverflow.com/questions/6222583/how-to-compare-strings – ivo Aug 26 '17 at 14:28
  • I agree with all the comments above, but first, you should be using the strcmp function instead of `=` (which does assignment, I think you meant `==`) and you have to make `load` a string, so: `"load"`. – Alexis Dumas Aug 26 '17 at 16:07

2 Answers2

2
if (input = load);

There are three mistakes with this line. The first is that you used the assignment operator = instead of comparison operator ==. The former assigns, the latter compares.

The second mistake is that you placed a semicolon after the parenthesis, indicating an empty body. Your compiler should have given you a warning about this.

Finally, there is no variable load. You mean to compare to string literal "load".

Fix to

if (input == "load")
    cout << "loading...\n";
lost_in_the_source
  • 10,998
  • 9
  • 46
  • 75
1

You probably intended the following

if (input == "load") {
 cout << "loading...";
}
stefan bachert
  • 9,413
  • 4
  • 33
  • 40