On a more serious note than my last post... :P I'm trying to delete leading spaces using
Obviously, I was expecting the output to be:
.erase(). However, I'm getting some weird bug that I can't understand. Maybe you guys can shed some light on the matter. :)darkness@linux:~$ cat eval.cpp
#include <cstdlib>
#include <iostream>
#include <string>
int main()
{
const std::string str = " foo ";
size_t spaces;
for(spaces = 0; str[spaces] == ' '; ++spaces);
str.erase(0, spaces - 1);
std::cout << "Number of leading spaces: " << spaces << std::endl;
std::cout << "New string: \"" << str << "\"" << std::endl;
return EXIT_SUCCESS;
}
darkness@linux:~$ g++ -o eval eval.cpp
eval.cpp: In function âint main()â:
eval.cpp:13: error: passing âconst std::stringâ as âthisâ argument of âstd::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::erase(typename _Alloc::rebind<_CharT>::other::size_type, typename _Alloc::rebind<_CharT>::other::size_type) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]â discards qualifiersObviously, I was expecting the output to be:
Number of leading spaces: 4
New string: "foo "