C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- std::array
- std::vector
- std::vector<T,Allocator>::push_back
- std::vector<T,Allocator>::assign
- std::vector<T,Allocator>::get_allocator
- std::vector<T,Allocator>::operator[]
- std::vector<T,Allocator>::front
- std::vector<T,Allocator>::at
- std::vector<T,Allocator>::pop_back
- std::vector<T,Allocator>::end, std::vector<T,Allocator>::cend
- std::vector<T,Allocator>::vector
- std::vector<T,Allocator>::~vector
- std::vector<T,Allocator>::operator=
- std::vector<T,Allocator>::back
- std::vector<T,Allocator>::data
- std::vector<T,Allocator>::begin, std::vector<T,Allocator>::cbegin
- std::vector<T,Allocator>::rbegin, std::vector<T,Allocator>::crbegin
- std::vector<T,Allocator>::rend, std::vector<T,Allocator>::crend
- std::vector<T,Allocator>::empty
- std::vector<T,Allocator>::size
- std::vector<T,Allocator>::max_size
- std::vector<T,Allocator>::reserve
- std::vector<T,Allocator>::capacity
- std::vector<T,Allocator>::shrink_to_fit
- std::vector<T,Allocator>::clear
- std::vector<T,Allocator>::insert
- std::vector<T,Allocator>::emplace
- std::vector<T,Allocator>::erase
- std::vector<T,Allocator>::emplace_back
- std::vector<T,Allocator>::resize
- std::vector<T,Allocator>::swap
- std::swap(std::vector)
- std::erase, std::erase_if (std::vector)
- operator==,!=,<,<=,>,>=,<=>(std::vector)
- std::vector çæ¨å¯¼æå¼
- std::map
- std::unordered_map
- std::priority_queue
- std::span
- std::forward_list
- std::deque
- std::list
- std::set
- std::multiset
- std::multimap
- std::unordered_set
- std::unordered_multiset
- std::unordered_multimap
- std::stack
- std::queue
- std::vector<bool>
- ç»ç¹ææ (C++17)
- 注é
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >容å¨åº >std::vector > std::vector<T,Allocator>::erase
std::vector<T,Allocator>::erase
| (1) | ||
| iterator erase( iterator pos ); |
(C++11 å) | |
| iterator erase( const_iterator pos ); |
(C++11 èµ·) | |
| (2) | ||
| iterator erase( iterator first, iterator last ); |
(C++11 å) | |
| iterator erase( const_iterator first, const_iterator last ); |
(C++11 èµ·) | |
ä»å®¹å¨æ¦é¤æå®çå ç´ ã
pos çå
ç´ ã[first; last) ä¸çå
ç´ ãéæ³åä½äºæ¦é¤ç¹æä¹åçè¿ä»£å¨ï¼å å« end() è¿ä»£å¨ã
è¿ä»£å¨ pos å¿
须忳ä¸å¯è§£å¼ç¨ãä»èä¸è½ä»¥ end() è¿ä»£å¨ï¼åæ³ï¼ä½ä¸å¯è§£å¼ç¨ï¼ä¸º pos çå¼ã
è¥ first==last åè¿ä»£å¨ first ä¸å¿
å¯è§£å¼ç¨ï¼æ¦é¤ç©ºèå´æ¯æ æä½ã
åæ°
| pos | - | æåè¦ç§»é¤çå ç´ çè¿ä»£å¨ |
| first, last | - | è¦ç§»é¤çå ç´ èå´ |
| ç±»åè¦æ± | ||
-T å¿
须满足å¯ç§»å¨èµå¼ (MoveAssignable) çè¦æ±ã
| ||
è¿åå¼
åéæåç§»é¤å ç´ çè¿ä»£å¨ã
è¥ pos æä»£æ«å
ç´ ï¼åè¿å end() è¿ä»£å¨ã
è¥å¨ç§»é¤å last == end() ï¼åè¿åæ´æ°ç end() è¿ä»£å¨ã
è¥ [first, last) 为空èå´ï¼åè¿å last ã
å¼å¸¸
䏿åºï¼é¤é T çèµå¼è¿ç®ç¬¦æå¼å¸¸ã
å¤æåº¦
线æ§ï¼è°ç¨ T ææå½æ°ç次æ°ä¸è¢«æ¦é¤çå ç´ æ°ç¸åï¼è°ç¨ T èµå¼è¿ç®ç¬¦ç次æ°ä¸ vector ä¸è¢«æ¦é¤å ç´ åçå ç´ æ°ç¸çã
示ä¾
#include <vector> #include <iostream> Â Â int main( ) { std::vector<int> c{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; for (auto &i : c) { std::cout << i << " "; } std::cout << '\n'; Â c.erase(c.begin()); Â for (auto &i : c) { std::cout << i << " "; } std::cout << '\n'; Â c.erase(c.begin()+2, c.begin()+5); Â for (auto &i : c) { std::cout << i << " "; } std::cout << '\n'; }
è¾åºï¼
0 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 1 2 6 7 8 9
åé
| æ¸
é¤å
容 (å ¬å¼æå彿°) |