0
for(auto it = prefixSet.begin();it!=prefixSet.end();it++)
    {
        string str = *it;
        if(prefixSet.count(str) > 1)
        {
            cout << prefixSet.count(str) << " " << str << endl;
            prefixSet.erase(it);
            cout << prefixSet.count(str) << " " << str << endl;
        }
    }

Prefixset is a multiset which has a string "d". After executing above code, I get the following output.

3 d
2 d

I was expecting it to delete all the instances and count to be 0.

What is that I am missing?

Anup Buchke
  • 5,210
  • 5
  • 22
  • 38

0 Answers0