如何让VC编的程序带参数运行
2个回答
展开全部
#include <string.h>
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
if (argc < 3)
{
cout << "Usage : test.exe /user:someone /pwd:password" << endl;
exit(-1);
}
const char *user = "someone";
const char *pswd = "something";
char *u = argv[1], *p = argv[2];
while (*u++ != ':');
while (*p++ != ':');
if (strcmp(u, user) || strcmp(p, pswd))
{
cout << "User name or Password invalid! exiting.." << endl;
exit(-1);
}
cout << "Hello, " << user << endl;
system("PAUSE");
return 0;
}
#include <iostream>
#include <cstdlib>
using namespace std;
int main(int argc, char **argv)
{
if (argc < 3)
{
cout << "Usage : test.exe /user:someone /pwd:password" << endl;
exit(-1);
}
const char *user = "someone";
const char *pswd = "something";
char *u = argv[1], *p = argv[2];
while (*u++ != ':');
while (*p++ != ':');
if (strcmp(u, user) || strcmp(p, pswd))
{
cout << "User name or Password invalid! exiting.." << endl;
exit(-1);
}
cout << "Hello, " << user << endl;
system("PAUSE");
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询