Simplified code snippet produces assertion string out of bounds error if I do not uncomment the if statement in main.
using namespace std;
size_t find_next_of(string & src, size_t pos) {
//size_t tmppos;
//if (pos != string::npos) {
return src.find_first_of('a', pos);
//}
//return string::npos;
}
int main( void ) {
string str ("a word and another.");
cout << str << '\n';
size_t found = str.find_first_of('a');
str[found]='X';
cout << "first = " << found << endl;
while (found != string::npos) {
found = find_next_of(str, found + 1);
//if (found != string::npos) {
str[found]='X';
cout << "next = " << found << endl;
//}
}
cout << str << '\n';
getchar();
return 0;
}
I'm ater suggestions for a way I'd not need to evaluate found in the while loop, while keeping my function call.
Appreciate any input.