如何访问C++中的一对元素?
答
如果你有
std::pair<std::string,std::pair<int,int>> pp{"string", {1, 42}};
然后
assert(pp.first == std::string{"string"});
assert(pp.second.first == 1);
assert(pp.second.second == 42);
全部通过
+0
谢谢你,这就是我的意思 –
你尝试过什么?你在使用诸如'.first','。second.first'和'.second.second'之类的东西时有问题吗? – TheUndeadFish
这只是我脑中的想法 –
我们看不到你的大脑,我们也不能调试它。尝试编写代码;如果遇到在Google和StackOverflow上搜索后无法解决的问题,请发布这些问题的详细信息。 –