using erase() in a loop like this!
来源:互联网 发布:日本原单 知乎 编辑:程序博客网 时间:2024/06/08 16:10
int main()
{
// Initialization
vector<int> iv;
for (size_t i = 0; i != 10; ++i)
{
iv.push_back(i);
}
// Print
for (vector<int>::iterator iter = iv.begin(); iter != iv.end(); ++iter)
{
printf("%d ", *iter);
}
printf("/n");
// Iterate and erase
for (vector<int>::iterator iter = iv.begin(); iter != iv.end(); /*No Increment Here*/)
{
if (*iter % 2)
{
iter = iv.erase(iter); // After this, iter will point to the first element beyond the erased one
}
else
{
++iter;
}
}
// Print
for (vector<int>::iterator iter = iv.begin(); iter != iv.end(); ++iter)
{
printf("%d ", *iter);
}
printf("/n");
// The end
system("PAUSE");
return 0;
}
- using erase() in a loop like this!
- Using Variables in ODI: Creating a Loop in a Package
- C++ STL erase in for loop
- using for loop in ssh
- Is there a way to loop through a table variable in TSQL without using a cursor?
- This webpage has a redirect loop
- This web page has a redirect loop
- How to parse a URI like this in Java http://translate.google.com/#zh-CN|en|你
- How To Loop A Map In Java
- [Amazon] Find loop in a singly linkedlist
- Mounting a disk image using the loop device
- Using a URDF in Gazebo
- Finding a Loop in a Singly Linked List
- tar: This does not look like a tar archive
- say something to myself at a moment like this
- This does not look like a tar archive - 解决方法
- Implementing Sugarcrm: A Step-by-step Guide to Using This Powerful Open Source Application in Your B
- 266. Like a rat in a hole. 瓮中之鳖
- WinCE中RTC驱动开发介绍
- 最常见的一款Js文字特效
- zoj 分类
- CodeSmith 公用代码共享方法
- 国庆的感触
- using erase() in a loop like this!
- 编译QT用到的各种库
- oracle分区表基本操作
- oracle中schema指的是什么?
- 推荐一本好书:《C++沉思录》
- 《RHL9入门与提高》读书笔记(2)
- 二分查找算法
- 数据库表关联
- 数据库设计的14个技巧(转)