1. <small id='rKenR'></small><noframes id='rKenR'>

        <bdo id='rKenR'></bdo><ul id='rKenR'></ul>
      <legend id='rKenR'><style id='rKenR'><dir id='rKenR'><q id='rKenR'></q></dir></style></legend>
      <tfoot id='rKenR'></tfoot>
      <i id='rKenR'><tr id='rKenR'><dt id='rKenR'><q id='rKenR'><span id='rKenR'><b id='rKenR'><form id='rKenR'><ins id='rKenR'></ins><ul id='rKenR'></ul><sub id='rKenR'></sub></form><legend id='rKenR'></legend><bdo id='rKenR'><pre id='rKenR'><center id='rKenR'></center></pre></bdo></b><th id='rKenR'></th></span></q></dt></tr></i><div id='rKenR'><tfoot id='rKenR'></tfoot><dl id='rKenR'><fieldset id='rKenR'></fieldset></dl></div>

      1. 如何在不进行插入的情况下检查 std::map 是否包含键?

        How to check if std::map contains a key without doing insert?(如何在不进行插入的情况下检查 std::map 是否包含键?)
        <legend id='4sq0Y'><style id='4sq0Y'><dir id='4sq0Y'><q id='4sq0Y'></q></dir></style></legend>

          <tbody id='4sq0Y'></tbody>

        <tfoot id='4sq0Y'></tfoot>

        <small id='4sq0Y'></small><noframes id='4sq0Y'>

              <bdo id='4sq0Y'></bdo><ul id='4sq0Y'></ul>

              1. <i id='4sq0Y'><tr id='4sq0Y'><dt id='4sq0Y'><q id='4sq0Y'><span id='4sq0Y'><b id='4sq0Y'><form id='4sq0Y'><ins id='4sq0Y'></ins><ul id='4sq0Y'></ul><sub id='4sq0Y'></sub></form><legend id='4sq0Y'></legend><bdo id='4sq0Y'><pre id='4sq0Y'><center id='4sq0Y'></center></pre></bdo></b><th id='4sq0Y'></th></span></q></dt></tr></i><div id='4sq0Y'><tfoot id='4sq0Y'></tfoot><dl id='4sq0Y'><fieldset id='4sq0Y'></fieldset></dl></div>
                1. 本文介绍了如何在不进行插入的情况下检查 std::map 是否包含键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我发现检查重复项的唯一方法是插入并检查 std::pair.second 是否为 false,但问题是这仍然会插入如果密钥未使用,而我想要的是 map.contains(key); 函数.

                  The only way I have found to check for duplicates is by inserting and checking the std::pair.second for false, but the problem is that this still inserts something if the key is unused, whereas what I want is a map.contains(key); function.

                  推荐答案

                  Use my_map.count( key );它只能返回0或1,本质上就是你想要的布尔结果.

                  Use my_map.count( key ); it can only return 0 or 1, which is essentially the Boolean result you want.

                  或者 my_map.find( key ) != my_map.end() 也可以.

                  这篇关于如何在不进行插入的情况下检查 std::map 是否包含键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
                  Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)

                        • <bdo id='Yebla'></bdo><ul id='Yebla'></ul>

                          <small id='Yebla'></small><noframes id='Yebla'>

                          <i id='Yebla'><tr id='Yebla'><dt id='Yebla'><q id='Yebla'><span id='Yebla'><b id='Yebla'><form id='Yebla'><ins id='Yebla'></ins><ul id='Yebla'></ul><sub id='Yebla'></sub></form><legend id='Yebla'></legend><bdo id='Yebla'><pre id='Yebla'><center id='Yebla'></center></pre></bdo></b><th id='Yebla'></th></span></q></dt></tr></i><div id='Yebla'><tfoot id='Yebla'></tfoot><dl id='Yebla'><fieldset id='Yebla'></fieldset></dl></div>
                          <legend id='Yebla'><style id='Yebla'><dir id='Yebla'><q id='Yebla'></q></dir></style></legend>

                              <tbody id='Yebla'></tbody>
                            <tfoot id='Yebla'></tfoot>