Visual Studio shows C++ ambiguity errors after adding if-statement

mattersonline picture mattersonline · Sep 30, 2014 · Viewed 8.3k times · Source

I'm having this weird code issue. In visual studio all of my 'cout's, 'cin's, and my 'system' have red squiggles and are marked as ambiguous code. The project still compiles fine and doesn't give me any errors or warnings but it's annoying and will stop me from knowing when I'm making an actual error. It all started when I added the 'if(argc > 0)' part and if I remove it then delete and retype 'using namespace std;' the squiggles disappear. Sadly when I retype the above 'if' statement the problem returns. I would really appreciate some help. Thanks people!

#include <string>
#include <iostream>
#include "chkString.h"
using namespace std;

int main(int argc, char * argv){
    int cipher;
    int encryption;
    string keyPhrase;
    string iFile;
    string oFile;
    chkString chk;
    cout << "Hello User!" << endl;
    if(argc > 0){
        cout << "Hello";
    }
    if(argc = 0){
        cout << "Enter '1' for Vigenere, or '2' for Playfair, or '0' to quit: ";
        cin >> cipher;

        while(cipher != 1 && cipher != 2 && cipher != 0){
            cout << "I'm sorry that is not a valid entry. "
                << "Please retry." << endl <<
                "Enter '1' for Vigenere, or '2' for Playfair, or '0' to quit: ";
            cin >> cipher;
        }
        if(cipher == 0){
            return 0;
        }

        cout << "Enter '1' for encryption, '2' for decryption: ";
        cin >> encryption;

        while(encryption != 1 && encryption != 2){
            cout << "I'm sorry that is not a valid entry. "
                << "Please retry." << endl <<
                "Enter '1' for encryption, '2' for decryption: ";
            cin >> encryption;
        }

        cout << "Enter the keyphrase: ";
        cin >> keyPhrase;

        while(!(chk.intCheck(keyPhrase))){
            cout << "I'm sorry that is not a valid entry. "
                    << "Please retry." << endl << "Enter keyphrase: ";
                cin >> keyPhrase;
        }

        cout << "Enter your output file name: ";
        cin >> oFile;

        cout << "Enter yout input file name: ";
        cin >> iFile;
    }
    cout << "Hello" << endl;
    system("pause");
    return 0;
}

Answer

rici picture rici · Sep 30, 2014

It's evident that most of that program will not ever be executed because:

if(argc = 0){
// ...
}

assigns 0 to argc and then tests false, because argc is now 0, so the code block is never executed.