【问题标题】:Print values from structure从结构中打印值
【发布时间】:2022-01-25 15:25:21
【问题描述】:

我有结构:

std::map<:string std::vector> someValues;

如何打印所有值,例如: 1、字符串 2、vector中的值?

我的 c++ 项目中有更多地图,我需要一些循环来打印所有值。

【问题讨论】:

    标签: c++ dictionary vector


    【解决方案1】:

    这可能适用于您想要的。

    for (const auto& [key, vec] : someValues) {
        std::cout << key << std::endl;
        for (const auto& val : vec) {
            std::cout << "    " << val << std::endl;
        }
    }
    

    【讨论】:

    • 这里可能需要一些解释(尤其是结构化绑定的使用)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-13
    • 2020-11-22
    • 1970-01-01
    相关资源
    最近更新 更多