getopt in C++ command line arguments with the options
<p>I am writing a simple program to have <code>-d</code> with a parameter along with the other arguments </p>

<p>I want them run with aa.cc with the following options</p>

<ul>
<li><code>aa -d 123 param1 param2</code> or</li>
<li><code>aa param1 param2 -d 123</code></li>
</ul>

<p>I have written the code in the following way</p>

<pre><code>    /* sample */

    char *level:
    while ((ch = getopt(argc, argv, "d:")) != EOF) {
        switch(ch) {
        case 'd':
            level = optarg;    
            debug = TRUE;
            break;
        default:
            usage();
            /*NOTREACHED*/
        }
    }
</code></pre>

<p>It is working fine when given as
<code>aa -d 123 param1 param2</code> but not 
when given as 
<code>aa param1 param2 -d 123</code>.</p>

<p>Can anyone please suggest how we can achieve that?</p>
