小编abc*_*cde的帖子

如何在C++中解析命令行参数?

如何在C++中有效地解析这个命令行?

program -parameter1=value1 -parameter2=value2 -parameter3=value3
Run Code Online (Sandbox Code Playgroud)

如何有效地删除参数和值的组合

-parameter=value
Run Code Online (Sandbox Code Playgroud)

我试图使用此代码,但它无法正常工作:

parameter[256], value[256],
while ( --argc > 0 )
{
   if ( *argv[argc] == '-' )
   {
       for ( char * text = argv[argc]; ; )
       {    
            switch ( * ( ++ text ) )
            {
                case '=' :
                {
                   *value = *(  text );
                    break;
                }

                default:
                {
                   *parameter = *text;
                }
            }
         }

       //Testing parameters and values
    }
}
Run Code Online (Sandbox Code Playgroud)

感谢您的意见和改进.

c++ command-line parsing

2
推荐指数
1
解决办法
692
查看次数

标签 统计

c++ ×1

command-line ×1

parsing ×1