Removing a character from a string

Posted by Prasanth Madhavan on Stack Overflow See other posts from Stack Overflow or by Prasanth Madhavan
Published on 2010-12-27T10:05:33Z Indexed on 2011/01/02 22:53 UTC
Read the original article Hit count: 311

Filed under:
|

i have a string. I want to delete the last character of the string if it is a space. i tried the following code,

str.erase(remove_if(str.begin(), str.end(), isspace), str.end());

but my g++ compiler gives me an error saying:

error: no matching function for call to ‘remove_if(__gnu_cxx::__normal_iterator<char*,
std::basic_string<char, std::char_traits<char>, std::allocator<char> > >,
__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>,
std::allocator<char> > >, <unresolved overloaded function type>)’

please help.

© Stack Overflow or respective owner

Related posts about c++

Related posts about string