title: Issues converting one string to another
body: <p>I want to convert date strVal="1992-12-12" or "1992-9-9" of the form to 19921212 &amp; 19920909. For doing so I have written following piece of code in C/C++. But the trouble is it converts 1992-12-12 to 1992012012. Can anyone guide me as to how show i fix this bug? I may also have inputs of the form "1992-9" and I would like to convert it to 19920900. Or "1992" to "19920000"</p>
  
  <pre><code>stringstream     collectTimeBegin;
  
  for (string::iterator it = strVal.begin(); it != strVal.end(); )
  {
        if (*it != '-')
        {
               cout&lt;&lt; "\n -- *it=" &lt;&lt; *it;
               collectTimeBegin &lt;&lt; *it;
               it++;
        }
        else
        {
             stringstream    si("");
             stringstream    sj("");
             int             i;               
  
             it++;
             si &lt;&lt; *(it + 1);
             sj&lt;&lt; *(it + 2);
             i = atoi((si.str()).c_str()), j = atoi((sj.str()).c_str());
             cout &lt;&lt; "\n i=" &lt;&lt; i &lt;&lt; "\t j=" &lt;&lt; j &lt;&lt; "\n";
             if ((i == 4) || (i == 5) || (i == 6) || (i == 7) || (i == 8) || (i == 9))
             {
                   cout &lt;&lt; "\n 1. *it=" &lt;&lt; *it;
                   collectTimeBegin &lt;&lt; *it;
                   it++;
             }
             else if ((j == 0) || (j == 1) || (j == 2) || (j == 3) || (j == 4) || 
                      (j == 5) || (j == 6) || (j == 7) || (j == 8) || (j == 9))
             {
                   string     str = "0";
  
                   cout &lt;&lt; "\n 2. *it=" &lt;&lt; *it;
                   collectTimeBegin &lt;&lt; str;
                   collectTimeBegin &lt;&lt; *it;
                   it++;
              }
         }
   }
  </code></pre>