Argument Definitions
Visual Studio 2010
The arguments in the prototype
int main( int argc[ , char *argv[ ] [, char *envp[ ] ] ] ); int wmain( int argc[ , wchar_t *argv[ ] [, wchar_t *envp[ ] ] ] );
allow convenient command-line parsing of arguments and, optionally, access to environment variables. The argument definitions are as follows:
The following example shows how to use the argc, argv, and envp arguments to main:
// argument_definitions.cpp
// compile with: /EHsc
#include <iostream>
#include <string.h>
using namespace std;
int main( int argc, char *argv[], char *envp[] ) {
int iNumberLines = 0; // Default is no line numbers.
// If /n is passed to the .exe, display numbered listing
// of environment variables.
if ( (argc == 2) && _stricmp( argv[1], "/n" ) == 0 )
iNumberLines = 1;
// Walk through list of strings until a NULL is encountered.
for( int i = 0; envp[i] != NULL; ++i ) {
if( iNumberLines )
cout << i << ": " << envp[i] << "\n";
}
}
goofy sample code
Shouldn't iLines be a boolean?
Also, the comments make it sound like the purpose of iLines is to predicate printing line numbers when in fact it predicates the printing of all output.
Also, the comments make it sound like the purpose of iLines is to predicate printing line numbers when in fact it predicates the printing of all output.
- 7/13/2010
- racarate
- 7/24/2010
- Thomas Lee
Note