iterator prob in for loop
A snippet of my code:
Code:
// cycle through list of words
for(list<string>::iterator i = inputFile.begin(); i != inputFile.end(); i++) {
string word = *i;
// compare to words in dictionary
for(list<string>::iterator j = loadedDictionary.begin(); j != loadedDictionary.end(); j+=2) {
string dicWord = *j;
if(word.compare(dicWord) == 0) { // if words are equal - fix
*i = *(j+1);
break;
}
}
}
I get the following errors and I'm not quite sure why:
Quote:
error: no match for 'operator+=' in 'j += 2'
error: no match for 'operator+' in 'j + 1'
The nexted for loop is required to look at every second string in the list. If a string math is found, then the dereferenced iterator (*i) must equal the j+1 dereferenced element in the list. What is wrong with the pointer arithmetic?