title: getopt fails to detect missing argument for option
body: <p>I have a program which takes various command line arguments. For the sake of simplification, we will say it takes 3 flags, <code>-a</code>, <code>-b</code>, and <code>-c</code>, and use the following code to parse my arguments:</p>
  
  <pre><code>    int c;
      while((c =  getopt(argc, argv, ":a:b:c")) != EOF)
      {
          switch (c)
          {
               case 'a':
                   cout &lt;&lt; optarg &lt;&lt; endl;
                   break;
               case 'b':
                   cout &lt;&lt; optarg &lt;&lt; endl;
                   break;
               case ':':
                   cerr &lt;&lt; "Missing option." &lt;&lt; endl;
                   exit(1);
                   break;
          }
      }
  </code></pre>
  
  <p>note: a, and b take parameters after the flag.</p>
  
  <p>But I run into an issue if I invoke my program say with</p>
  
  <pre><code>./myprog -a -b parameterForB
  </code></pre>
  
  <p>where I forgot parameterForA, the parameterForA (represented by optarg) is returned as <code>-b</code> and parameterForB is considered an option with no parameter and optind is set to the index of parameterForB in argv.</p>
  
  <p>The desired behavior in this situation would be that <code>':'</code> is returned after no argument is found for <code>-a</code>, and <code>Missing option.</code> is printed to standard error. However, that only occurs in the event that <code>-a</code> is the last parameter passed into the program.</p>
  
  <p>I guess the question is: is there a way to make <code>getopt()</code> assume that no options will begin with <code>-</code>?</p>