A list of multiset.

S

SUPER_SOCKO

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;

}

I wait for your suggestion.

Thank you.
 
K

Karl Heinz Buchegger

SUPER_SOCKO said:
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: (e-mail address removed) Web: www.gascad.com

Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top