gpt4 book ai didi

c++ - 两张 map 不匹配

转载 作者:行者123 更新时间:2023-11-30 03:47:25 26 4
gpt4 key购买 nike

我可以在两个 map 上使用 std::mismatch 吗?

documentation ,有一个使用字符串的示例,我认为它与 vector 类似。

答案来自Intersection of two STL maps很有用,但我不确定如何在 map 上使用 std::mismatch

如果可以,是否也可以用于嵌套 map ?

最佳答案

是的,std::map 具有双向迭代器,而 std::mismatch 需要输入迭代器作为其参数:

std::map<int, int> A {{1, 2}, {2, 3}, {4, 4}};
std::map<int, int> B {{1, 2}, {2, 4}, {4, 4}};
auto miss = std::mismatch(A.begin(), A.end(), B.begin());
std::cout << "{" << miss.first->first << ", " << miss.first->second
<< "} != {" << miss.second->first << ", "
<< miss.second->second << "}" << std::endl;

输出:

{2, 3} != {2, 4}

LIVE DEMO

关于c++ - 两张 map 不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33680698/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com