A list of multiset.

Discussion in 'C++' started by SUPER_SOCKO, Mar 1, 2005.

  1. SUPER_SOCKO

    SUPER_SOCKO Guest

    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.
    SUPER_SOCKO, Mar 1, 2005
    #1
    1. Advertising

  2. 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
    Karl Heinz Buchegger, Mar 1, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arthur J. O'Dwyer

    multiset segfault

    Arthur J. O'Dwyer, Jun 17, 2004, in forum: C++
    Replies:
    10
    Views:
    715
    Dave Townsend
    Jun 18, 2004
  2. John Harrison

    simple multiset question

    John Harrison, Aug 4, 2004, in forum: C++
    Replies:
    3
    Views:
    314
    John Harrison
    Aug 4, 2004
  3. Replies:
    0
    Views:
    312
  4. gacek

    multiset example

    gacek, Nov 8, 2005, in forum: C++
    Replies:
    2
    Views:
    1,489
    gacek
    Nov 10, 2005
  5. =?iso-8859-1?q?Jo=E3o_Correia?=

    Order items within multiset AND Find object on multiset

    =?iso-8859-1?q?Jo=E3o_Correia?=, Feb 26, 2007, in forum: C++
    Replies:
    2
    Views:
    467
Loading...

Share This Page