c++ STL 映射复制将布尔值设置为 true
我的 stl 地图有问题。最初,我用这样的数据填充地图。
//loop
pair< int, int > xy (x,y);
currentMap.insert( make_pair(xy), value); //map< pair<int, int>, bool>
prevMap.insert( make_pair(xy), value);
// End Loop
然后我根据一些规则删除一个元素,如下所示。
currentMap.erase( make_pair(xy) );
后来我交换了两个地图对象。
prevMap = currentMap;
交换后,所有元素都被分配为 true。如果我搜索元素 xy... *编辑-我领先了。对不起。
i = currentMap.find( make_pair(xy) );
return i->second; // Always true after swap.
真理总是会被评估为真理。初始化地图会将 bool 值设置为 true 吗?我可以用 false 来初始化所有 bool 吗?
谢谢。
I'm having a problem with stl map. Initially I fill the map with data like so.
//loop
pair< int, int > xy (x,y);
currentMap.insert( make_pair(xy), value); //map< pair<int, int>, bool>
prevMap.insert( make_pair(xy), value);
// End Loop
Then I delete an element according to some rules like so.
currentMap.erase( make_pair(xy) );
I later do a swap of the two map objects.
prevMap = currentMap;
After the swap all of the elements are assigned to true. If I search for element xy...
*edit - i got a ahead of myself. Sorry.
i = currentMap.find( make_pair(xy) );
return i->second; // Always true after swap.
truth will always evaluate to true. Will initializing a map set the bool value to true? Can I initialise with all bools at false.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法将地图的值初始化为任何值。您只能将值与键一起插入。如果您想在密钥丢失时返回 false,您的最后一个代码片段应该如下所示:
You can't initialize the map's values to anything. You can only insert values along with the key. Your last code snippet should look like this if you want to return false when the key is missing: