vector words compare

Hello, i don't understand 1 little thing:
if (words[i-1]!=words[i]) // is this a new word?

This code snippet must to compare 2 words in vector to see if they are the same,
but why it compares all the words, and not the only [i] and [i-1] ?

Is it vector type not the same for comparing as an array of strings?
Last edited on
but why it compares all the words

It doesn't?
It compares the word at position i with the previous one.
whoops ! :)

i didn't noticed this line

sort(words.begin(), words.end()); // because of it i have this result?



because of it i have this result?

Huh?
The line sorts the vector, that's all.
If the vector is sorted then identical words will be adjacent.
Topic archived. No new replies allowed.