I'm having trouble with the switch case function lately.
I want to compare a character from a string with a bunch of signs and after it found a ; or % it's supposed to delete the rest of the string
I tried it this way:
for (string::iterator itString=currentString.begin() ; itString!=currentString.end() ; ++itString){
char currentCharacter = *itString;
switch(currentCharacter)
case ' ': currentString.erase(itString);
break;
case ';': currentString.erase(itString, currentString.length());
break;
case '%': currentString.erase(itString, currentString.length());
break;
but that gives me an error: error: no matching function for call to 'std::basic_string<char, std::char_traits<char>, std::allocator<char> >::erase(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >&, size_t)'|
the function is erase(int pos, int len). itString is an iterator. there is no conversion (sort of..). anyway, you can access string elements without iterators. use [].
It's actually pretty nice with the iterator since it makes the code pretty small and nice to read.
The problem just was that I godda use string.end() while this is an iterator. string.length() is and int I guess???
Atleast that would explain the error.
If you're interested just check out the cplusplus.com reference for string::erase