Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ MFC与命令行的接口_C++_Command Line_Mfc - Fatal编程技术网

C++ MFC与命令行的接口

C++ MFC与命令行的接口,c++,command-line,mfc,C++,Command Line,Mfc,我想在我的MFC应用程序中添加一个命令行接口,以便提供命令行参数。这些参数将配置应用程序的启动方式 然而,我不知道如何连接这两个。如果可能的话,我该怎么做呢?MFC有一个CCommandLineInfo类来完成这项工作-请参阅文档。以下是我在MFC应用程序中的操作方法: int option1_value; BOOL option2_value; if (m_lpCmdLine[0] != '\0') { // parse each command line token c

我想在我的MFC应用程序中添加一个命令行接口,以便提供命令行参数。这些参数将配置应用程序的启动方式


然而,我不知道如何连接这两个。如果可能的话,我该怎么做呢?

MFC有一个CCommandLineInfo类来完成这项工作-请参阅文档。

以下是我在MFC应用程序中的操作方法:

int option1_value;
BOOL option2_value;

if (m_lpCmdLine[0] != '\0')
{
     // parse each command line token
     char seps[] = " "; // spaces
     char *token;
     char *p;
     token = strtok(m_lpCmdLine, seps); // establish first token            
     while (token != NULL)
     {
          // check the option
          do    // block to break out of         
          {
               if ((p = strstr(strupr(token),"/OPTION1:")) != NULL)
               {
                    sscanf(p + 9,"%d", &option1_value);
                    break;
               }

               if ((p = strstr(strupr(token),"/OPTION2")) != NULL)
               {
                    option2_value = TRUE;
                    break;
               }
          }
          while(0); 

          token = strtok(NULL, seps);       // get next token           
     }
}   // end command line not empty

CCommandLineInfo的东西使用起来真的很乏味。在增加臃肿的顺序时,我建议使用TCALP(TealPcTimeC++命令行解析器)或Booost程序选项(),也可以在其他非MFC C++应用程序中使用这些库,甚至在其他操作系统中使用这些库。TCLAP可以配置为支持Windows样式的参数,即以“/”开头,而不是以“-”开头的POSIX参数()

谢谢!这正是我要找的!