STL allows duplicate pairs?

The second insert with the same key is a no-op. It simply returns an iterator pointing to the existing element.

std::map::insert() has a return value, which you should check.

It is of type std::pair<iterator,bool>. The second element of the pair tells you whether the element has been inserted, or whether there was already an existing entry with the same key.

cout << namemap.insert(pair<string,char>("yogendra",'a')).second << endl;
cout << namemap.insert(pair<string,char>("yogendra",'b')).second << endl;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)