且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-24 20:57:16

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() 也可以.