1.传递参数的exe,参数在s中,以空格隔开
#include <iostream>
#include <string>#include <Windows.h>
using namespace std;
int main(int argc,char *argv[])
{
cout<<"输入要传递的参数"<<endl;
string s;
getline(cin,s);
HINSTANCE hNewExe1 = ShellExecuteA(NULL, "open", //调用程序
"D:\\Documents\\Visual Studio 2010\\Projects\\传参\\Debug\\接受参数.exe"
,s.c_str(),NULL,SW_SHOW);
system("pause");
return 0;
}
2接受参数的exe,
#include <iostream>
#include <string>
#include <Windows.h>
using namespace std;
int main(int argc,char *argv[])
{
cout<<argc<<"个参数"<<endl;
for(int i=0;i<argc;i++)
{
cout<<argv[i]<<endl;
}
system("pause");
return 0;
}
3.int main(int argc,char *argv[]),不传递任何参数时候,argc代表是参数个数,argv是参数的数组argc[0]是第一个参数,为exe文件路径,argv[1]是第二个参数,