STL

Please can any one clear me difference between map and set in STL?

with example.
Last edited on
In a map, there is the key and the element. By using a key you get the element.
(Maps are sometimes called "associative arrays" because they're actually the general form of an array.)

    KEY     ELEM
map<string, int> msi;

    KEY           ELEM
msi["Hello"]    = 203;
msi["Car"]      = 11;


As you can see, in a map the key and the element are distinct things.
And that's the difference between a map and a set.

In a set, each element is its own key.
thanx Cafish666 for you reply.

can you please check following points are correct:-


1. List and Set contains elements in sorted order .
2. we can not change elements value from set.
3. there is also key value pair in set but in set we don't have to set key.
4. which one es more efficient?
5. Example were er should use map or set?
Topic archived. No new replies allowed.