title: c++ terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr:
body: <p>I am getting this error when running:</p>
  
  <p>terminate called after throwing an instance of 'std::out_of_range'
  what(): basic_string::substr:</p>
  
  <p>I am brand new, any other tips would be appreciated as well.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  using namespace std;
  
  int main()
  {
      string name;
      int position = 1;
      string letter;
  
      cout &lt;&lt; "Enter in your full name seperated by a space: ";
      getline (cin, name);
  
      cout &lt;&lt; name.substr(0, 1);
  
      while (position &lt;= name.length())
      {
          position++;
          letter = name.substr(position, 1);
  
          if (letter == " ")
          {
              cout &lt;&lt; name.substr(position + 1, 1) &lt;&lt; " ";
          }
      }
  
      cout &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>