title: Remove space chars from end of string C++
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/216823/whats-the-best-way-to-trim-stdstring">What&#39;s the best way to trim std::string</a>  </p>
  </blockquote>
  
  
  
  <p>I have a string:</p>
  
  <pre><code>std::string foo = "This is a string    "; // 4 spaces at end
  </code></pre>
  
  <p>How would I remove the spaces at the end of the string so that it is:</p>
  
  <pre><code>"This is a string" // no spaces at end
  </code></pre>
  
  <p>please note this is an example and not a representation of my code. I do not want to hard code:</p>
  
  <pre><code>std::string foo = "This is a string"; //wrong
  </code></pre>