zoukankan      html  css  js  c++  java
  • 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;
    }

  • 相关阅读:
    POJ 2154
    POJ 1286
    Polycarp's problems
    Greedy Change
    Goods transportation
    Ugly Problem
    Happy Matt Friends
    Dense Subsequence
    Ray Tracing
    Batch Sort
  • 原文地址:https://www.cnblogs.com/whiteIcrow/p/5012655.html
Copyright © 2011-2022 走看看