访问地图数据结构中的结构元素

Accessing elements of structure inside a map datastructure

本文关键字:结构 元素 地图 数据结构 访问      更新时间:2023-10-16

我有这样的结构,并映射数据结构,如:

#include <map>
struct category {
        int id;
        std::string name;
};
std::map<int, category> categories;

现在,使用类别,我想显示在结构类别中的元素"名称"。但我无法访问它。有人能帮忙吗?

感谢

您不能访问它是什么意思?

categories[0].name;

应该足够了。