Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > A list of multiset.

Reply
Thread Tools

A list of multiset.

 
 
SUPER_SOCKO
Guest
Posts: n/a
 
      03-01-2005
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.
 
Reply With Quote
 
 
 
 
Karl Heinz Buchegger
Guest
Posts: n/a
 
      03-01-2005
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Collections List : Converting from List '<Column <String1,String2>>' to 'List <String1>' asil klin Java 28 03-05-2011 01:59 AM
Memory issues when storing as List of Strings vs List of List OW Ghim Siong Python 2 11-30-2010 12:22 PM
Appending a list's elements to another list using a list comprehension Debajit Adhikary Python 17 10-18-2007 06:45 PM
Why does list.__getitem__ return a list instance for subclasses ofthe list type? dackz Python 0 02-06-2007 04:44 PM
Difference Between List x; and List x(); , if 'List' is a Class? roopa C++ 6 08-27-2004 06:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57