title: Reverse string function causes crash when accommodating 'space-bar'
body: <p>Testing Environment: Visual Studio 2010</p>
  
  <p>I am trying to include 'space-bar' as part of a users input for reversing their string. There are two issues that I've come across so far. </p>
  
  <ol>
  <li><p>if I only type in one word/character, the program crashes.</p></li>
  <li><p>if I type in multiple characters with spaces, the first character/word gets skipped, the rest print, program does not crash.</p></li>
  </ol>
  
  <hr>
  
  <p>Here is the code (I've left out parts of the code because they work just fine with or without the piece of code that's giving me issues):</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  void RevStrng(string &amp;inpu, int &amp;entry) 
  {
      if (entry == inpu.size()-1) //return the length of the string, minus 1 byte
          return;
      int stored = inpu.size() - 1 - entry; //store the rearranged string in variable stored
      string firstLetr = inpu.substr(1,stored); //starting character for rearrangement
      string restOfLetr = inpu.substr(stored+1,inpu.size()); //remaining characters for rearrangement
      inpu = firstLetr + inpu.substr(0,1) + restOfLetr; //store rearrangement in pointer inpu
      RevStrng(inpu,++entry); //print rearranged string until 0 bytes left
  
  };
  int main()
  {
  
  ...
  ...
  ...
  
      //Taking user input, and printing it backwards
      cout &lt;&lt; "///Display string Backwards///" &lt;&lt; endl;
      string sentnce; 
      int syze = 0;
      cout&lt;&lt;"Please enter characters to be read backwards: ";
      cin&gt;&gt;(sentnce);
      getline(cin, sentnce);
      RevStrng(sentnce, syze);
      cout &lt;&lt; "Your entry backwards is: "&lt;&lt; sentnce &lt;&lt; "\n" &lt;&lt; endl;
  
  ...
  ...
  ...
  }
  </code></pre>
  
  <p>I can't figure out what I'm doing wrong. I know they do the same thing but i even tried changing .length() to .size() and still same situation. When I try to adjust the numerical portions of my function, I get a StackOverFlowException. I have a feeling that <code>string firstLetr = inpu.substr(1,stored);</code> is causing the issue...but I don't know what to do, or where to look.</p>
  
  <p>So I welcome all suggestions, if at all possible PLEASE try to hint out to me where to look at in the function, otherwise if you feel the hint would be a dead give away then up to you (but even if it is I do still want to try and figure it out). </p>
  
  <p>Thank you!</p>