Strings in if() statements

Hi all
So I'm having a bit of an issue;
Here's my code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
back_to_prompt:
        cout << prompt;
            cin >> input;

        if(input == "nmap")
        {
            cout << "Usage: \"nmap <target>\"" << endl;
            goto back_to_prompt;
        }

        if(input == "nmap 23.56.132.98")
        {
            cout << "Scanning host please wait . . ." << endl;
            Sleep(1500);
            cout << "PORT\tSTATE\tPROTOCOL" << endl;
            cout << "21/tcp\tOPEN\tftp"<< endl;
        }


if I type in 'nmap'; then it does as it's supposed to and goes to the first if statement. However if I type in 'nmap 23.56.132.98' it doesn't do the if-statement it was supposed to and goes to the first one.

How do I fix this?
Last edited on
Try using getline(cin,input); instead of cin >> input;. The reason for this is because when you type in "nmap 23.56.132.98" std::cin only reads until any whitespace, in this case it will stop after nmap which makes your fist if statement true.
Wow thanks friend!
Solved my problem.
Topic archived. No new replies allowed.