title: Using getopt_long (C++) how do I code up a long & short option to both require arguments?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;getopt.h&gt;
  
  #define no_argument 0
  #define required_argument 1 
  #define optional_argument 2
  
  
  int main(int argc, char * argv[])
  {
    std::cout &lt;&lt; "Hello" &lt;&lt; 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, &amp;index);
  
      switch (iarg)
      {
        case 'h':
          std::cout &lt;&lt; "You hit help" &lt;&lt; std::endl;
          break;
  
        case 'v':
          std::cout &lt;&lt; "You hit version" &lt;&lt; std::endl;
          break;
  
        case 's':
          std::cout &lt;&lt; "You hit stuff" &lt;&lt; std::endl;
          break;
      }
    }
  
    std::cout &lt;&lt; "GoodBye!" &lt;&lt; std::endl;
  
    return 0; 
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>./a.out -s
  Hello
  You hit stuff
  GoodBye!
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>./a.out --stuff
  Hello
  ./a.out: option `--stuff' requires an argument
  GoodBye!
  </code></pre>
  
  <p><strong>Conflict needing resolved:</strong> Both -s &amp; --s should say: <strong>./a.out: option `--stuff' requires an argument</strong> when used without proceeding arguments following the command. But only --stuff does? Does anyone know what I'm missing here?</p>
  
  <p><strong>Desired result:</strong></p>
  
  <pre><code>./a.out -s
       Hello
       ./a.out: option `--stuff' requires an argument
        GoodBye!
  
  ./a.out --stuff
       Hello
       ./a.out: option `--stuff' requires an argument
       GoodBye!
  </code></pre>