title: Infinite loop using string.substr(post,len)
body: <p>Could you figure out why it keeps looping infinitely in the console? The programmer's supposed to list out each character of a user-inserted string and next to each unique character, in brackets, it's supposed to display the number of times that character occurs in the string... no idea why.</p>
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  int main () {
    string input;
    cout &lt;&lt; &quot;input string: &quot; , cin &gt;&gt; input;
    sort (input.begin() , input.end());
    while (!input.empty()) {
      int j{1}, i{0};
      while (input.at(i) == input.at(i+1)) {
        j++;
        i++;
      }
      cout &lt;&lt; input.at(i) &lt;&lt; &quot; (&quot; &lt;&lt; j &lt;&lt; &quot;), &quot;;
      input.substr(i);
    }
    return 0;
  }
  </code></pre>