Page 1 of 1

Command line argument

Posted: Sun Jul 19, 2009 9:44 pm
by Jane
Hi,

how to accept command line arguments in C++ ? (how to accept more than one argument?)

Thanks

Jane

Re: Command line argument

Posted: Tue Jul 21, 2009 3:26 pm
by Neo
To accept command line arguments, we need to define the main() as follows.

Code: Select all

int main ( int argc, char *argv[] )
argc is the number of arguments passed in command line
argv is an array of C strings with the value of the arguments passed to your program
Note that argv[0] is always the name of your program