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

    <legend id='EtJRM'><style id='EtJRM'><dir id='EtJRM'><q id='EtJRM'></q></dir></style></legend>

    1. <i id='EtJRM'><tr id='EtJRM'><dt id='EtJRM'><q id='EtJRM'><span id='EtJRM'><b id='EtJRM'><form id='EtJRM'><ins id='EtJRM'></ins><ul id='EtJRM'></ul><sub id='EtJRM'></sub></form><legend id='EtJRM'></legend><bdo id='EtJRM'><pre id='EtJRM'><center id='EtJRM'></center></pre></bdo></b><th id='EtJRM'></th></span></q></dt></tr></i><div id='EtJRM'><tfoot id='EtJRM'></tfoot><dl id='EtJRM'><fieldset id='EtJRM'></fieldset></dl></div>
    2. <tfoot id='EtJRM'></tfoot>
        <bdo id='EtJRM'></bdo><ul id='EtJRM'></ul>

      向量、结构和 std::find

      时间:2023-09-16

      <legend id='dI9C8'><style id='dI9C8'><dir id='dI9C8'><q id='dI9C8'></q></dir></style></legend>

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

              • <bdo id='dI9C8'></bdo><ul id='dI9C8'></ul>
                <i id='dI9C8'><tr id='dI9C8'><dt id='dI9C8'><q id='dI9C8'><span id='dI9C8'><b id='dI9C8'><form id='dI9C8'><ins id='dI9C8'></ins><ul id='dI9C8'></ul><sub id='dI9C8'></sub></form><legend id='dI9C8'></legend><bdo id='dI9C8'><pre id='dI9C8'><center id='dI9C8'></center></pre></bdo></b><th id='dI9C8'></th></span></q></dt></tr></i><div id='dI9C8'><tfoot id='dI9C8'></tfoot><dl id='dI9C8'><fieldset id='dI9C8'></fieldset></dl></div>
                  <tbody id='dI9C8'></tbody>
              • <tfoot id='dI9C8'></tfoot>
              • 本文介绍了向量、结构和 std::find的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                再次使用向量.我希望我不会太烦人.我有一个这样的结构:

                Again me with vectors. I hope I'm not too annoying. I have a struct like this :

                struct monster 
                {
                    DWORD id;
                    int x;
                    int y;
                    int distance;
                    int HP;
                };
                

                所以我创建了一个向量:

                So I created a vector :

                std::vector<monster> monsters;
                

                但现在我不知道如何搜索向量.我想在向量中找到怪物的 ID.

                But now I don't know how to search through the vector. I want to find an ID of the monster inside the vector.

                DWORD monster = 0xFFFAAA;
                it = std::find(bot.monsters.begin(), bot.monsters.end(), currentMonster);
                

                但显然它不起作用.我只想遍历结构的 .id 元素,但我不知道该怎么做.非常感谢帮助.谢谢!

                But obviously it doesn't work. I want to iterate only through the .id element of the struct, and I don't know how to do that. Help is greatly appreciated. Thanks !

                推荐答案

                std::find_if:

                it = std::find_if(bot.monsters.begin(), bot.monsters.end(), 
                        boost::bind(&monster::id, _1) == currentMonster);
                

                如果没有boost,也可以编写自己的函数对象.看起来像这样

                Or write your own function object if you don't have boost. Would look like this

                struct find_id : std::unary_function<monster, bool> {
                    DWORD id;
                    find_id(DWORD id):id(id) { }
                    bool operator()(monster const& m) const {
                        return m.id == id;
                    }
                };
                
                it = std::find_if(bot.monsters.begin(), bot.monsters.end(), 
                         find_id(currentMonster));
                

                这篇关于向量、结构和 std::find的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在为每个执行 a 时从 std::vector 中擦除? 下一篇:连接两个向量的最佳方法是什么?

                相关文章

                最新文章

                <tfoot id='iapFq'></tfoot>

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

                  <legend id='iapFq'><style id='iapFq'><dir id='iapFq'><q id='iapFq'></q></dir></style></legend>

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