c++ how to use erase

hi all, i'm new here

int wh=0;
wh=(int)str.find(' ');
if(wh!=string::npos)
if(str.size())
str.erase(str.find(' '));

in fact i want remove a space if find it
but with this code remove all after the space
for e.g

i have this str "hi all"
and after, the str is only "hi"
One of the std::string::erase() overloads takes two integers (a,b), b being a default parameter. When b is omitted, std::string::erase() removes all elements from a to the end of the string.
To remove only one element, either pass 1 as the second parameter, or use one of the overloads that take iterators.

http://www.cplusplus.com/reference/string/string/erase/
Topic archived. No new replies allowed.