vector iterator not incrementable For information on how your program can cause an an assertion Failure, see the Visual c + + documentation on asserts
2014-07-14 20:59
555 查看
#include <list> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { list<int> slist; list<int>::iterator iter; slist.push_back(1); slist.push_back(5); slist.push_back(11); for(iter = slist.begin(); iter != slist.end(); ++iter) { if(11 == *iter) slist.erase(iter); } return 0; }
问题(vector iterator not incrementable For information on how your program can cause an an assertion Failure, see the Visual c + + documentation on asserts. (Press Retry to debug the application)
这个比较典型,当删除的元素不是最后一个,则没有太大问题。
VS2008下运行这个,当slist.erase(iter);当要删除的元素是slist中的最后一个的时候,执行erase之后
iter就指向end了,再次进入for循环,执行++iter就出错了。。。(erase会是迭代器失效)
默认的是const iterator 是会出现这种错误的:
判断
if (it != m_Bullsts.end()) //迭代器失效
{
it++;
}
相关文章推荐
- VA番茄助手提示The security key for this program currently stored on your system does not appear to be vali
- VA安装时弹出The security key for this program currently stored on your system does not appear
- The security key for this program currently stored on your system does not appear to be valid for th
- Unable to start debugging on the web server. The web server is not configured correctly. See help for common configuration errors. Running the web page outside of the debugger may provide further information.
- VS 安装助手,弹出“The security key for this program currently stored on your system does not appear to be ”
- VS 安装助手,弹出“The security key for this program currently stored on your system does not appear to be ”
- "Format" did not complete normally. Please see the log for more information. 解决
- 修复VirtualBox "This kernel requires the following features not present on the CPU: pae Unable to boot – please use a kernel appropriate for your CPU"
- Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server.
- android 老是弹出 "Copy" did not complete normally. Please see the log for more information.
- Android Studio ON Linux 报错:An error occurred while creating the AVD. See idea.log for details,解决方法
- 《How hard can it be? Estimating the difficulty of visual search in an image》和 PPT
- How to get the RGB values for a pixel on an image on the iphone
- 23 How can you reverse the effects of an ALTER DISKGROUP … DROP DISK command if it has not yet compl
- How_to_build_an_ARM/DSP_Hello_World_program_on_the_DaVinci_EVM 续
- How can I get an object's absolute position on the page in Javascript?
- how can you see if an application program offers a function module exit
- How can I throw an exception without losing the original stack trace information in .NET?
- 【iOS】Could not launch Verify the Developer App certificate for your account is trusted on your devic
- "Copy" did not complete normally. Please see the log for more information