vector::erase returns incompatible iterator in debug build
关于std::vector中erase的用法http://www.cplusplus.com/reference/vector/vector/erase/
#include <vector>
struct WordCoordinate {
int x;
int y;
int z;
};
struct Mypoint
{
int x;
int y;
};
int main()
{
std::vector<WordCoordinate> m_worldCoorPoint;
std::vector<Mypoint> m_screenPoint;
Mypoint point;
for (int i=;i<=;i++)
{
WordCoordinate m_w;
m_w.x=+i;
m_w.y=+i;
m_w.z=+i;
m_worldCoorPoint.push_back(m_w);
point.x = i+;
point.y = i+;
m_screenPoint.push_back(point);
point.x = *i+;
point.y = *i+;
m_screenPoint.push_back(point);
} int thershold =; // if distance low than thershold delete the point
std::vector<WordCoordinate>::iterator itw=m_worldCoorPoint.begin();
std::vector<Mypoint>::iterator it=m_screenPoint.begin();
int idex = ;
while(it!=m_screenPoint.end())
{ printf("delete point index %d\n",idex);
printf("cur point (%d %d)",(*it).x,(*it).y); if( idex==)
{ it=m_screenPoint.erase(it,it+);
itw=m_worldCoorPoint.erase(itw);
} idex++;
}
system("pause");
return ;
}
当程序运行到if( idex==2)后再返回while就会出错,这个是微软官方bug http://connect.microsoft.com/VisualStudio/feedback/details/545013解决方法安装sp1
在这个版本下会有错:时间有限来不及详细写,有空补充bug原因

vector::erase returns incompatible iterator in debug build的更多相关文章
- stl vector erase
C++ Code 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 ...
- MSDN 中 对vector::erase()的解释.xml
pre{ line-height:1; color:#f0caa6; background-color:#2d161d; font-size:16px;}.sysFunc{color:#e54ae9; ...
- C++中使用vector.erase()需要注意的事项
本人菜鸟一枚.. 今天在用vector.erase()的时候,发现总是不能把应该erase掉的东西erase干净. 举个栗子: vector<int> num_vec; num_vec.p ...
- vector.erase用法注意事项
转自->这里 vector::erase():从指定容器删除指定位置的元素或某段范围内的元素 vector::erase()方法有两种重载形式 如下: iterator erase(iterat ...
- vector erase
vector::erase 从指定容器删除指定的元素 两个重载: iterator erase (iterator position);删除指定位置position的元素,并返回删除元素的下一个元素的 ...
- vector.erase();vector.clear();map.erase();
vector::erase()返回下一个iter: STL中的源码: //清除[first, last)中的所有元素 iterator erase(iterator first, iterator l ...
- map/vector erase
问题核心:erase之后迭代器是否失效 vector调用erase之后,该迭代器之后的迭代器都失效: map调用erase之后,其他迭代器并不会失效. vector<int> vecDat ...
- 解决 React-Native mac 运行报错 error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by ope
React-Native 开发的项目,Android 方面没有任何问题,IOS 就是无法跑起来,报错信息如下: mac 10.14.4 xcode 10.2.1 error Failed to bui ...
- C++ vector erase函数的使用注意事项
最近使用了顺序容器的删除元素操作,特此记录下该函数的注意事项. 在C++primer中对c.erase(p) 这样解释的: c.erase(p) 删除迭代器p所指向的元素,返回一个指向被删元素 ...
随机推荐
- 《3D数学基础:图形与游戏开发》勘误
最近读这本书,读到四元素的乘法时,自己推导了一下公式,然后懵了,多方查阅,确定是书籍中的笔误(我读的是中文翻译版): 具体在Page147: 上图所示,在第二处明显与第一处的公式不一样. 在维基百科上 ...
- 浅淡Webservice、WSDL三种服务访问的方式(附案例)
Webservice Webservice是使应用程序以与平台和编程语言无关的方式进行相互通信技术. eg:站点提供访问的数据接口:新浪微博.淘宝. 官方解释:它是一种构建应用程序的普遍模型,可以在任 ...
- power desinger 学习笔记<八>
转-PowerDesigner 把Comment复制到name中和把name复制到Comment 在使用PowerDesigner对数据库进行概念模型和物理模型设计时,一般在NAME或Comment中 ...
- SGU 149. Computer Network
时间限制:0.25s 空间限制:4M: 题意: 给出一颗n(n<=10000)个节点的树,和n-1条边的长度.求出这棵树每个节点到最远节点的距离: Solution: 对于一个节点,我们可以用D ...
- Perl 中级教程 第5章课后习题
5. 9. 1. 练习1 [5 分钟] 先不要运行程序, 看看你能否判断出这程序的哪部份出了问题?如果你看不出 来, 就可以运行一相程序, 得到些暗示, 来看是否能修改好: my %passenger ...
- 在easyui dialog的子页面内如何关闭弹窗
因项目需要在dialog中添加滚动条,所以就在div中加了iframe: <div id="applyRefundDialog" style="display:no ...
- jquery获取form表单内容以及绑定数据到form表单
在日常开发的过程中,难免会用到form表单,我们需要获取表单的数据保存到数据库,或者拿到后台的一串json数据,要将数据绑定到form表单上,这里我写了一个基于jquery的,formHelp插件,使 ...
- ECSHOP在商品详细页面上获取该商品的顶级分类id和名称
在 goods.php 文件, 找到 $smarty->assign('goods', $goods); 在它上面增加下面代码: 方法一: $cat_arr = get_parent_cats( ...
- YII 小部件 yii小部件查看方法 小物件做的表单
要使用小部件,可以先到总文件去找 framework/yiilite文件里面搜索“CAtiveForm” (如果觉得小部件的radio布局有点难看,可以在外面定义,具体可以在控制器里面定义) 如下 ...
- img超出div width时, jQuery动态改变图片显示大小
参考: 1. http://blog.csdn.net/roman_yu/article/details/6641911 2. http://www.cnblogs.com/zyzlywq/archi ...