I'm trying to compile the code of Accelerated C++, page 105: the split function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
vector<string> split (string& str) {
vector<string> ret;
typedef string::const_iterator iter;
iter i = str.begin();
while (i != str.end()) {
i = find_if (i, str.end(), not_space);
iter j = find_if (i, str.end(), space);
if (i != str.end())
ret.push_back(string(i,j));
i = j;
}
return ret;
}
This code gives the error message "No matching function for the call to 'find_if' ". Now, if I change the typedef to ::iterator instead of const_iterator, the error goes away.
Why can't I use const_iterator in this example? Thanks for all help!