#include <iostream.h>
#include <stdlib.h>
/*argc是外部命令参数的个数,argv[]存放的是各参数的内容*/
int main(int argc,char *argv[])
{
int a,b,c;
if(argc==1 ||argc>3)
return 0;
cout<<"argc="<<argc<<endl;
cout<<"argv[0]="<<argv[0]<<endl;
cout<<"argv[1]="<<argv[1]<<endl;
cout<<"argv[2]="<<argv[2]<<endl;
a=atoi(argv[1]);
b=atoi(argv[2]);
c=a+b;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"a+b="<<c<<endl;
return 0;
}
附录:
Visual C++6.0下的编译方法:
Project/Setting…/Debug/Program argument:输入 10 20