How do I get a const_iterator using auto?

前端 未结 8 1795
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-13 08:18

First question: is it possible to \"force\" a const_iterator using auto? For example:

map usa         


        
8条回答
  •  星月不相逢
    2020-12-13 09:06

    You can use auto to "track" a type or "deduce" a type: // deduce auto city_it = usa.find("New York");

    // track auto city_it = std::map::const_iterator( usa.find("New York"));

    Also, watch is modern c++ style talks by Herb Sutter, which covers most of these type deductions guidance. https://youtu.be/xnqTKD8uD64

提交回复
热议问题