Use strcmp (http://www.cplusplus.com/reference/cstring/strcmp/) for the C-string comparisons. It needs header <cstring>. I always get confused which way round is true and which is false (actually, it returns integers 0 or 1, which implicitly convert to false or true). You probably need !strcmp here.
i tried running the program through the command prompt and it works fine.
but if i go under Project in VS and "Project name" properties and under Debugging with Locals Windows Debugger and i supply the arguments under Command Arguments as -r test.txt , the program returns -1 not sure why.
will something like this work if( argv[1] == "-r") ?
No (for the reasons @jonnin gave you). Nearest possibilities are if ( strcmp( argv[1], "-r" ) == 0 )
or, equivalently (as in my code sample): if ( !strcmp( argv[1], "-r" ) )
or, converting one argument to a string: if( string( argv[1] ) == "-r")
Sadly, you can't overload the == operator for two c-strings (but it didn't stop me trying!).
i tried running the program through the command prompt and it works fine.
but if i go under Project in VS and "Project name" properties and under Debugging with Locals Windows Debugger and i supply the arguments under Command Arguments as -r test.txt , the program returns -1 not sure why.
If you are referring to my code sample then it will return -1 for file not found (look at the code). So, you need to put your test.txt in whichever folder VS looks in (which I'm afraid I can't help you with).
If you can run it from the command line then perhaps you don't need VS ...
No, it returns a number less than, equal to, or greater than zero, depending on whether the first argument compares less than, equal to, or greater than the second. In other words, -1, -25 and 974 are all legal return values.
The right way to handle strcmp is to always compare the result to zero.
I don't think it's part of the standard, but see if your environment supports getopt(). This is how UNIX has processed command lines for decades.
No, it returns a number less than, equal to, or greater than zero, depending on whether the first argument compares less than, equal to, or greater than the second.
My apologies - thank-you for the correction, @dhayden.
Fortunately, all the code samples are simply relying on whether the c-strings are equal (strcmp returns 0) or not equal (something other than 0).