首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::forward_list::erase_after

iterator erase_after( const_iterator pos );

(1)

(since C++11)

iterator erase_after( const_iterator first, const_iterator last );

(2)

(since C++11)

从容器中移除指定的元素。

1%29移除以下元素pos...

2%29移除范围内的元素。(first; last)...

参数

pos

-

iterator to the element preceding the element to remove

first, last

-

range of elements to remove

返回值

1%29 Iterator对被擦除元素后面的元素,或end()如果不存在这样的元素。

2%29last

复杂性

1%29常数。

2%29直线距离firstlast...

二次

代码语言:javascript
复制
#include <forward_list>
#include <iterator>
#include <iostream>
int main()
{
    std::forward_list<int> l = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
 
    //    l.erase( l.begin() ); // ERROR: No function erase
 
    l.erase_after( l.before_begin() ); // Removes first element
 
    for( auto n : l ) std::cout << n << " ";
    std::cout << '\n';
 
    auto fi= std::next( l.begin() );
    auto la= std::next( fi, 3 );
 
    l.erase_after( fi, la );
 
    for( auto n : l ) std::cout << n << " ";
    std::cout << '\n';
}

二次

产出:

二次

代码语言:javascript
复制
2 3 4 5 6 7 8 9
2 3 6 7 8 9

二次

另见

clear

clears the contents (public member function)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券