相关疑难解决方法(0)

使用getopt_long(C++)如何为两个需要参数的长短选项编码?

#include <iostream>
#include <getopt.h>

#define no_argument 0
#define required_argument 1 
#define optional_argument 2


int main(int argc, char * argv[])
{
  std::cout << "Hello" << std::endl;

  const struct option longopts[] =
  {
    {"version",   no_argument,        0, 'v'},
    {"help",      no_argument,        0, 'h'},
    {"stuff",     required_argument,  0, 's'},
    {0,0,0,0},
  };

  int index;
  int iarg=0;

  //turn off getopt error message
  opterr=1; 

  while(iarg != -1)
  {
    iarg = getopt_long(argc, argv, "svh", longopts, &index);

    switch (iarg)
    {
      case 'h':
        std::cout << "You hit help" << std::endl;
        break;

      case …
Run Code Online (Sandbox Code Playgroud)

c++ getopts getopt-long

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

标签 统计

c++ ×1

getopt-long ×1

getopts ×1