title: Finding a substring from input
body: <p>For my project, one of the options for an input is "I n" where n is a number. I am trying to get that input in an if statement for "I" from a substring, and then getting the number to eventually use stringstream to turn it into an integer.</p>
  
  <p>Here is my test code right now:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  int main(int argc, const char * argv[])
  {
      cout &lt;&lt; "Type in \"I 2\": " &lt;&lt; endl;
      string in = "";
      string numstr = "";
  
      while(in != "Q" &amp;&amp; in != "q")
      {
          cin &gt;&gt; in;
  
          //Input cases
          if(in.substr(0,1) == "I")
          {
              numstr = in.substr(1,1); //numstr is the number in string form
              cout &lt;&lt; in &lt;&lt; "+" &lt;&lt; numstr &lt;&lt; endl; //I want it to output "I+2"
                                                  //but it outputs "I+"
          }
          else
          {
  
              cout &lt;&lt; "That was not an option. Try again." &lt;&lt; endl;
          }
  
      }
      return 0;
  }
  </code></pre>
  
  <p>Right now the output is:</p>
  
  <pre><code>I+
  That was not an option. Try again.
  </code></pre>
  
  <p>What can I change to get it to recognize "2"? When I change the substring to (2,1) I get an out_of_range exception</p>