|
From: Ioannis V. <no...@ya...> - 2001-11-23 04:48:42
|
argv is an array of C-string pointers which has stored the arguments
given in command line. argv[0] is the name of the program itself. argc
is the number of argv elements and is at least 1 (the name of the
executable). **argv is also *argv[]. The second is the more notationally
correct (because argv is an array of c-strings). So here is some ANSI
C++ 1998 code demonstrating this:
=20
=20
#include <iostream>
#include <cstdio>
=20
int main(int argc, char *argv[])
{
using namespace std;
=20
cout<<"The total number of arguments including the filename of the
program,\nargc: "<<argc<<endl;
=20
cout<<"\nAnd now the arguments only:\n";
=20
for(int i=3D1; i<argc; i++)
cout<<argv[i]<<" ";
=20
cout<<endl;
=20
getchar();
}
=20
How i executed it:
=20
C:\c>temp 1 test
The total number of arguments including the filename of the program,
argc: 3
=20
And now the arguments only:
1 test
=20
=20
=20
Hope you got it.
=20
=20
Ioannis
=20
* Ioannis Vranos
* Programming pages: http://www.noicys.f2s.com
<http://www.noicys.f2s.com/>=20
* Alternative URL: http://run.to/noicys
=20
=20
-----Original Message-----
From: dev...@li...
[mailto:dev...@li...] On Behalf Of
Joh...@ao...
Sent: Friday, November 23, 2001 3:47 AM
To: dev...@li...
Subject: [Dev-C++] (no subject)
#include <iostream.h>
#include <stdio.h>
//QUESTION: Using what feature on the compiler to enter the 'argv'?
void main(int argc, char** argv)
{
int a =3D 10;
int b =3D a + argc;
cout<<" b =3D a + argc: "<<b<<endl;
int d =3D a + int(argv);//
cout<<" d =3D a + argv: "<< d<<endl;
getchar();
}
//I enter the 'argc' through the input of 'Parameter' Button then hit
//the 'Exection' to run the program. But I dont know how/where to enter
the
//'argv' through the command line.....
Very appreciate your help..........=20
|