What's an effective way to parse command line parameters in C++?

前端 未结 6 2035
滥情空心
滥情空心 2021-02-09 05:46

Is there a really effective way of dealing with command line parameters in C++?

What I\'m doing below feels completely amateurish, and I can\'t imagine this is how comma

6条回答
  •  悲&欢浪女
    2021-02-09 06:16

    I am using getopt() under windows/mingw :

    while ((c = getopt(myargc, myargv, "vp:d:rcx")) != -1) {
            switch (c) {
            case 'v': // print version
                printf("%s Version %s\n", myargv[0], VERSION);
                exit(0);
                break;
            case 'p': // change local port to listen to
                strncpy(g_portnum, optarg, 10);
                break;
    ...
    

提交回复
热议问题