title: Why is this function printing an x instead of 1?
body: <p>I have written a small program for run length encoding.</p>
  
  <pre><code>void runLengthEncoding (string&amp; str)
  {
      int k=0;
      int count =1;
      for (unsigned i=1, count=1; i&lt;str.size(); ++i)
      {
              if ( str[i] == str[k])
              {
                      count +=1;
              }
              else
              {
                      str[++k] = count+'0';
                      str[++k] = str[i];
                      count = 1;
              }
      }
      str[++k] = count + '0';
  
      str.resize(k);
  }
  </code></pre>
  
  <p>When I call this function using</p>
  
  <pre><code>string s = "wwwwaaadexxxxxx";
  runLengthEncoding (s);
  cout &lt;&lt; endl &lt;&lt; s;
  </code></pre>
  
  <p>It is printing - <code>"w4a3d1e1x"</code>
  It should print - <code>"w4a3d1e1x6"</code></p>
  
  <p>My doubt is why it is not printing the last count?</p>