Can I easily iterate over the values of a map using a range-based for loop?

后端 未结 4 1211
醉梦人生
醉梦人生 2021-02-03 20:38

Is it possible to iterate over all of the values in a std::map using just a "foreach"?

This is my current code:

std::map

        
4条回答
  •  执笔经年
    2021-02-03 21:13

    std::map foo;
    
    for (const auto& any : foo) {
        MyClass *j = any.second;
        j->bar();
    }
    

    in c++11 (also known as c++0x), you can do this like in C# and Java

提交回复
热议问题