5

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;
}
mattersonline
  • 183
  • 1
  • 10
  • Unrelated, but `if(argc = 0)` actually assigns 0 to `argc` then converts to a bool expression as `false` and nothing would get executed in the branch (that is most of your posted code). Also, `argc` includes the program name in the count, so it should always be at least 1. – SleuthEye Sep 30 '14 at 01:36
  • `argc` will [typically never be zero](http://stackoverflow.com/questions/8113786/executing-a-process-with-argc-0) for an application launched from the command line of an ordinary desktop computing environment. The `argv[0]` pointer will usually point to a string that is the name of the application launched. "command line arguments" will usually be in positions `argv[1]` and later. – lone gold Sep 30 '14 at 01:44
  • Alter the title/tags if it is *really* "Visual Student". – user2864740 Sep 30 '14 at 02:03

2 Answers2

4

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.

rici
  • 234,347
  • 28
  • 237
  • 341
3

You have an error:

if(argc = 0){    // should be ==

Not a compile error, but a logic error. Possibly it is causing Visual Studio code analysis to realize that you are saying:

if(0) {   

which is never true, so code analyzer knows the block can't execute.

codenheim
  • 20,467
  • 1
  • 59
  • 80