Click to See Complete Forum and Search --> : stl set question


neo_the_1
March 10th, 2005, 11:06 AM
hi,

CString buff( "abc" );
std::set< CString > s;
s.insert( buff );
s.insert( buff );
s.insert( buff );
s.insert( buff );
s.insert( buff );
s.insert( buff );

does the set inserts "abc" once ?

thanks

Philip Nicoletti
March 10th, 2005, 11:17 AM
Yes. Just examine s.size()

If you want it inserted more than once, use multiset instead of set

neo_the_1
March 10th, 2005, 11:24 AM
thanks Philip.
let me extend the question, when i insert n items to the set,
and than iterate on the set, do i get the items at the same
order they were inserted ?

Philip Nicoletti
March 10th, 2005, 11:29 AM
No. set orders the items. By default, it uses operator <
but you can provide the constructor with a predicate also.

neo_the_1
March 10th, 2005, 12:44 PM
thanks again :)