Hey guys. Question is. I need an example of a working code for a multiset. Hope theres someone out there who can help me on this, kind soul. Probably a multiset with a set of a grocery lists; not numbers you know.. for eg... {eggs, tomatoes, onions, chicken, shampoo..etc} you know... I've been doing this and so stuck and i've this assignment due really soon. help me on this pls. thanks

You say you've been doing this, so could you post what you have so far?

commented: Beat me to it @_@ +3
#include<iostream>
#include<set>
using namespace std;

int main() {
    multiset<long> A;

    for (int k=1; k<=5; k++) A.insert(k);
    A.insert(3);

    cout <<"The size of A is  " << A.size() << endl;

    multiset<long>::iterator ai;
    cout << "The elements of A are: ";
    for (ai = A.begin(); ai != A.end(); ai++) {
        cout << *ai << " ";
    }
    cout << endl;
    return 0;
}

This is what i've been trying to edit. Firstly the characters like the onions cabbages or eggs... Instead of a number set. And i also need a counter when these items are selected because multisets allows multiple elements with equal values. just in case the 'shopping item is selected twice.'

Please put code in code tags. Highlight your code and click the # button above the message box. (If you're editing your post, you have to click the "Go Advanced" button below the message box before you can see the # button)

Is that code you wrote yourself or did it come with the assignment? If it was provided, I take it that you have to modify it to adapt to the assignment requirements?

I'll start off with one hint: you need to change something in the line: multiset<long> A;

So you can't see the code? It works for one thing. But it's too simple. There is no requirements for this assignment. I was the one who thought of the shopping list set. I mean... How do i change the set of numbers? Wats the code for it? string? char?

I can see the code, but it's hard to read - that's why code tags exist. Please use it - it will motivate more people to help you out.

I haven't tested the code myself but I won't doubt that it compiles and runs...you still haven't answered my question though. There's no such thing as an assignment that doesn't have any requirements. You're going to have to come clean if you want anyone to help you.

Read this too (it should answer most of your questions): http://www.cplusplus.com/reference/stl/multiset/

I guess A.size(5) will increase the size to 5.

I guess A.size(5) will increase the size to 5.

No, it returns the current size of the set. Read the link above.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.