Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/146.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.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++ 我可以使用popt库一次读取选项的两个值吗?_C++_Linux - Fatal编程技术网

C++ 我可以使用popt库一次读取选项的两个值吗?

C++ 我可以使用popt库一次读取选项的两个值吗?,c++,linux,C++,Linux,我正在编写一个使用popt库读取参数的示例。我的代码如下 enum { INPUT_NAME=1, SYMBOL }; int main(int argc, char **argv) { char filename[ 128 ], symbol[32]; memset(filename, 0x0, 128); memset(symbol, 0x0, 32); struct poptOption opttable[] = { {

我正在编写一个使用popt库读取参数的示例。我的代码如下

enum
{
   INPUT_NAME=1,
   SYMBOL
};
int main(int argc, char **argv)
{
    char filename[ 128 ], symbol[32];
    memset(filename, 0x0, 128);
    memset(symbol, 0x0, 32);

    struct poptOption opttable[] =
    {
        { "file", 'f', POPT_ARG_STRING, filename, INPUT_NAME, "filenames to read", "list of files we need to read" },
        { "symbol", 'r', POPT_ARG_STRING, symbol, SYMBOL, "symbol to view", NULL },
        POPT_AUTOHELP
        POPT_TABLEEND
    };
    poptContext options_socket = poptGetContext( NULL, argc, ( const char **)argv, opttable, 0 );
    int optionvalue(0);
    while( optionvalue > -1 )
    {
        optionvalue = poptGetNextOpt( options_socket );
        if(optionvalue == INPUT_NAME)
        {
           strcpy(filename, poptGetOptArg( options_socket ));
           printf("filename you are giving as input is :%s\n", filename);
        }
        else if( optionvalue == SYMBOL)
        {
           strcpy(symbol, poptGetOptArg( options_socket ));
           printf("symbol you are giving as input is :%s\n", symbol);
        }
    }
    return 0;
}
通过使用此代码,我能够读取每个选项的单个值。是否有任何方法可以使用单个选项获取值列表

我目前的程序是这样工作的

sample run to my program: ./popt -f file1.txt file2.txt -r symbol1
OUTPUT:
filename you are giving as input is :file1.txt
symbol you are giving as input is :symbol1
DESIRED OUTPUT:
filename you are giving as input is :file1.txt
filename you are giving as input is :file2.txt
symbol you are giving as input is :symbol1

使用popt库可以吗

我认为它可以通过使用poptGetArgs函数来实现

这里没有看到任何关于linux中popt库的
C++
。我没有找到任何与popt相关的关键字。这就是为什么我要用c++和linux关键字。这似乎不起作用。对PoptGetAgs的第一个调用获取第一个参数,第二个调用获取NULL。