Command line argument

C, C++, Visual C++, C++.Net Topics
Post Reply
Jane
Corporal
Corporal
Posts: 10
Joined: Sun Jul 19, 2009 9:19 pm

Command line argument

Post by Jane » Sun Jul 19, 2009 9:44 pm

Hi,

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

Thanks

Jane
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: Command line argument

Post by Neo » Tue Jul 21, 2009 3:26 pm

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
Post Reply

Return to “C/C++ Programming”