小编Bob*_*bog的帖子

C++ 11 - 基于范围的二维地图循环

我有一个二维地图,我这样说:

typedef std::map<std::string, std::map<std::string, Objective>> objectives_t;
Run Code Online (Sandbox Code Playgroud)

我想将这个2d地图的内容保存到文件中.

所以我尝试了类似的东西,受到我在网络上找到的一些代码的启发:

for (auto const &subject : m_objectives) {
    for (auto const &objective : m_objectives[subject.first]) {
        //Print the objective
    }
}
Run Code Online (Sandbox Code Playgroud)

但是,当然,这不起作用.我该怎么办?我不确定什么是主题和目标(他们是一些迭代器吗?).

在第二行,我得到:

error: passing 'const objectives_t {aka const std::map<std::basic_string<char>, std::map<std::basic_string<char>, Objective> >}' as 'this' argument of 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::basic_string<char>; _Tp = std::map<std::basic_string<char>, Objective>; _Compare = std::less<std::basic_string<char> >; _Alloc = std::allocator<std::pair<const std::basic_string<char>, std::map<std::basic_string<char>, Obj|
Run Code Online (Sandbox Code Playgroud)

c++ dictionary multidimensional-array auto c++11

1
推荐指数
1
解决办法
1186
查看次数

标签 统计

auto ×1

c++ ×1

c++11 ×1

dictionary ×1

multidimensional-array ×1