duplicates - 为什么我的那套对包含重复项?
问题描述
我对一组包含不一致重复项的 pair<int,int> 感到困惑。集合的第一个元素被正确插入,然后,在插入第 k 对之后,集合中的所有对都被替换为新的 int 值的重复对。
该集合在循环中填充如下
//the coordinates are stored in vector of pair<double,double> with dimension N :
vector<pair<double,double> > coordPairs(N);
//populate "coordPairs"
...
std::set <std::pair<int,int> > occupiedCellList;
for(int i=0; i<coordPairs.size(); i++)
{
double x, y;
x = coordPairs[i].first;
y = coordPairs[i].second;
int row = (y - ymin) / cellSizeInMeters;
int col = (x - xmin) / cellSizeInMeters;
occupiedCellList.insert(make_pair(row,col));
}
即使我在 row 和 col 的表达式中使用 floor 或 trunc ,该集合仍然包含重复项。如何解释这种行为?
谢谢。
解决方案
我解决了我的问题。
似乎是重复的不是。“错误”来自 QT 创建器中的调试器,它错误地显示了集合元素。
当使用集合迭代器显示集合的 std::cout 元素时,所有元素都正常。
set<pair<int,int>> s;
...
//populate elements of s
...
set<pair<int,int>>::iterator it = s.begin();
while(it!=s.end())
{
cout<< it->first << ", " << it->second << endl;
it++;
}
推荐阅读
- ios - 颤振:Chewie videoplayer 视频可见,但从 IOS 设备上传视频时视频的声音不起作用
- ios - `Identifiable` 一致性返回类型泛型作为变量
- typescript - Typescript:使用 ES6 解构整个 props 对象并提供默认值
- vb.net - 如何在 WebBrowser 中打开 WinForm Framework 3.5 中的 Angular 项目?
- python - 过滤numpy字符数组
- azure - Azure ARM 无法解析 | 字符
- java - 如何从用户那里获得 @requestBody bean 类字段的别名
- r - 如果其他列匹配 100%,则查找一列中值的最接近匹配
- c# - .Net Core,Eventhub:身份验证失败,因为远程方已关闭传输流
- macos - 如果 listStyle 为 SidebarListStyle(),onMove 将停止工作