C++写一个带参数运行的程序

#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;
}

原文地址:https://www.cnblogs.com/whiteIcrow/p/5012655.html