本文介绍了擦除STL List容器中的第n个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何删除 STL 列表容器中的第n个元素.
谁能帮助我.

Hi,
How to erase an n-th element in STL List container.
Can Any one help me.

推荐答案

std::list<int> mylist;
std::list<int>::iterator it;

// Fill the list here
for (int i=0; i<10; i++)
    mylist.push_back (i);

// Init the iterator to point the 1-th element
it = mylist.begin();

// Advance to n-th element (for example we want to erase the 6-th 
// element and "it" points to first elemnt, so we have to advance 5 elements)
std::advance(it, 5);

// Erase the 6-th element
mylist.erase(it);



:)



:)


这篇关于擦除STL List容器中的第n个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:15