Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do you pass parameters from command line in C++?

Status
Not open for further replies.

Goku81

Programmer
Mar 27, 2001
34
US
Hey All,
Easy Question but don't know how it's done.
I know in Java you can pass parameters when you call your program like this
<c:\java\bin>java myprogram &quot;parameter1&quot; &quot;parameter2&quot;
and you can use those strings for whatever you want via
args[] array.
how do you do this in C++?
 
Hello,

#include <iostream.h>

int main(int argc,char *argv[])
{
int i;
cout << &quot;Number of arguments &quot;<< argc << &quot;\n&quot;;
for (i=0;i<argc;i++)
{
cout << &quot;Argument &quot; << i << &quot; '&quot; << argv << &quot;'\n&quot;;
}
return 0;
}

Wouter Dijkslag

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top