473,322 Members | 1,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

A list of multiset.

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.
Jul 23 '05 #1
1 1494
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: kb******@gascad.at Web: www.gascad.com

Fuer sehr grosse Werte von 2 gilt: 2 + 2 = 5
Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Der Andere | last post by:
I need to implement a sorted (ordered) list. STL has no sorted list type as far as I know. Is there a (straight) way to implement a sorted list using STL? BTW: The type of items in the list will...
10
by: Arthur J. O'Dwyer | last post by:
I'm seeing a bug at the moment that I can't track down. It's part of a moderately large program, but here is a small program that exhibits the bug on gcc. (The program code follows at the bottom...
3
by: John Harrison | last post by:
If you insert equal values into a multiset is it specified what order they will have in the multiset. For instance, what should be the output of this program, is it defined? #include <set>...
5
by: Dale Marchand | last post by:
I'm trying to use an object in two different multiset containers, each with it's own sort method. For the most frequently used, I overrode the operator< method in the class, and for the second I...
2
by: =?iso-8859-1?q?Jo=E3o_Correia?= | last post by:
class CScore { public: int L; int C; CScore(int l, int c) { L = l; C = c;
9
by: neil.johnston | last post by:
I have a cut down example program that uses multiset to order some data. The data arrives from various sources and has a time stamp, data with identical timestamps can arrive and due to fifo's and...
2
by: parvtb | last post by:
Thanks for your patience to read the entire post to understand my confusion I have the user-defined class "tools": class tools{ public: tools( ......) {} friend bool operator<...
4
Digital Don
by: Digital Don | last post by:
Hi, I was looking at the MultiSet STL structure with some "less" keyword. I was told that we can use the "MultiSet" STL structure to automatically sort the content. Is it possible to store and...
3
by: orzeech | last post by:
Hi everyone! I have a following problem: #include<iostream> #include<set> using namespace std;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.