STL good pit

About multiset, the following conclusions:

. 1 multiset < int > S;
 2 s.insert ( . 3 );
 . 3 s.insert ( . 3 );
 . 4 COUT << s.count ( . 3 ); // result output 2 
. 5 s.erase ( . 3 );
 . 6 COUT < <s.count ( . 3 ); // result output 0

Thus attention should have several analog multiset. A small amount of data can be an array of a hash.

 

About map, the following conclusions:

1 Map < int , int > MP;
 2  int main () {
 . 3      MP [- 1 ] = 1 ;
 . 4      mp.clear ();
 . 5      COUT << MP [- 1 ]; // at some environments, output 1 
6 }

This shows a clear map of the pit, consider using map.erase (map.begin (), map.end ()).

Guess you like

Origin www.cnblogs.com/St-Lovaer/p/12216057.html