SUPER_SOCKO wrote:
>
> I am new to STL. I don't know how to access a multiset of a list.
> My code is the following:
>
> #include <list>
> #include <iostream>
> #include <set>
>
> using namespace std;
>
> typedef multiset <int, less<int> > Int_Bag;
> // typedef list <Int_Bag> lib;
>
> void testContainer (void) {
> list <Int_Bag> ListBag;
>
> Int_Bag ib;
> ib.insert(5);
> ib.insert(2);
> ib.insert(7);
> ListBag.push_back(ib);
>
> cout << "Size of the list is " << ListBag.size() << endl; // output 1
> list <Int_Bag>::iterator ListBag_Iter;
>
> for(ListBag_Iter = ListBag.begin(); ListBag_Iter != ListBag.end(); ++ListBag_Iter)
> ; // I need some help.
> // for(ib_Iter = lb_Iter->iterator(); ib_Iter != lb_Iter->end(); ++ib_Iter)
> // cout << *(lb_Iter) << endl;
>
A ListBag_Iter is an iterator into a list of Int_bag objects. Dereferencing that
iterator thus leaves you with an Int_Bag object. Thus you access that object
just like an other Int_Bag object, just replacing the object with a dereferenced
iterator.
for(ListBag_Iter = ListBag.begin(); ListBag_Iter != ListBag.end(); ++ListBag_Iter) {
Int_Bag::iterator ib_Iter;
for( ib_Iter = ListBag_Iter->begin(); ib_Iter != ListBag_Iter->end(); ++ib_Iter )
cout << *ib_Iter << endl;
}
--
Karl Heinz Buchegger, GASCAD GmbH
Teichstrasse 2
A-4595 Waldneukirchen
Tel ++43/7258/7545-0 Fax ++43/7258/7545-99
email:
Web:
www.gascad.com
Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5