Tell me that in this code this line is executed cout<<(i->find("r")==-1 The result on screen 100 is not very clear, since we have the symbol 'r' in each word.

 #include<iostream> #include<string> #include<set> using namespace std; int main() { set<string>ss; ss.insert("Petrov"); ss.insert("Borov"); ss.insert("Abzalov"); ss.insert("Borov"); for(set<string>::iterator i= ss.begin();i!= ss.end();++i) cout<<(i->find("r")==-1); cin.get(); } 

    1 answer 1

    Actually (i-> find ("r") == - 1) should return a boolean value of true or false. Why this construction is needed, I do not understand. And it returns not 100, but the numbers 1 0 0. Ie in the first name there is no letter (r), and in the others there is.

    • Why, there is the letter r in "Petrov". - Roman1
    • @ Roman Ponomarenko, if you want to see 1, if the word has "r", then you should write not == , but != . - avp
    • @ Roman Ponomarenko you use a container of type set, and the first name in it will be Abzalov, then Borov, then Petrov, and that’s all, there are three non-repeating names. In the set container, duplicates are deleted. - perfect