0

I have this structure, and map datastructure like :

#include <map>

struct category {
        int id;
        std::string name;
};

std::map<int, category> categories;

Now, using categories I want to display element "name" which is in structure category. But I am not able to access it. Can anyone help?

Thanks

1 Answer 1

2

What do you mean you can't access it?

categories[0].name;

should be enough.

Sign up to request clarification or add additional context in comments.

6 Comments

Unless categories is const
categories[0].name would represent the name for the first element ,right?
@GWW categories is declared as std::map<int, category> categories;
@UnderDog no, the element with key 0.
@luchian : Pardon me for my ignorance, I didnt understand it well. structure category is key for my map function. There are 10 elements in my map function and each one has a name. Now I want to access member "name" of structure for each element, so by using categories[0].name, I would be able to do that?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.