如何在 unordered_map 中存储 2 个以上的变量? [英] How to store more than 2 variables in an unordered_map?

查看:54
本文介绍了如何在 unordered_map 中存储 2 个以上的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 std::unordered_map 中存储 2 个以上的变量?

How can I store more than 2 variables in an std::unordered_map?

我想要这样的东西:

std::unordered_map<string, int, int, int> mapss = {{"a",1,1,1},{"b",1,2,3}};

推荐答案

如果 string 是键,其余都是值,那么您可以将值设为 tuple.

If the string is the key, and the rest are values, then you could have the value be a tuple.

unordered_map<string, tuple<int, int, int>> mapss

如果你不知道有多少个值,你可以使用 vector

Of if you don't know how many values will be there, you can use a vector

unordered_map<string, vector<int>> mapss

这篇关于如何在 unordered_map 中存储 2 个以上的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆