title: How to use string.substr() function?
body: <p>I want to make a program that will read some number in string format and output it like this: if the number is 12345 it should then output 12 23 34 45 . I tried using the substr() function from the c++ string library, but it gives me strange results - it outputs 1 23 345 45 instead of the expected result. Why ?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  int main(void)
  {
      string a;
      cin &gt;&gt; a;
      string b;
      int c;
  
      for(int i=0;i&lt;a.size()-1;++i)
      {
          b = a.substr(i,i+1);
          c = atoi(b.c_str());
          cout &lt;&lt; c &lt;&lt; " ";
      }
      cout &lt;&lt; endl;
      return 0;
  }
  </code></pre>