|What does the test do? It looks to see if the previous word we printed is different from|
the one we are about to print (words[i–1]!=words[i]) and if so, we print
that word; otherwise, we do not. Obviously, we can’t talk about a previous
word when we are about to print the first word (i==0), so we first test for
that and combine those two tests using the || (or) operator:
if (i==0 || words[i–1]!=words[i]) // is this a new word?
|I want to understand how is it comparing the current string to the whole vector.|
|Line number 17 is doing the actual work. But I don't understand how is it doing it.|
i==0is true the second expression
words[i–1]!=words[i]is not evaluated.
i != 0the expression
i–1would be invalid.