[C/C++] std::vector::erase() Reference
반응형
std::vector::erase
iterator erase( iterator pos ); | (until C++11) | |
iterator erase( const_iterator pos ); | (since C++11) | |
(2) | ||
iterator erase( iterator first, iterator last ); | (until C++11) | |
iterator erase( const_iterator first, const_iterator last ); | (since C++11) | |
Removes specified elements from the container.
1) Removes the element at
pos
.2) Removes the elements in the range
[first; last)
.Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #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'; } | cs |
output
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
Ref:
http://en.cppreference.com/w/cpp/string/byte/vector
반응형
'IT > C, C++' 카테고리의 다른 글
[JSONCPP] JsonCpp 다운로드 및 컴파일 방법 (0) | 2017.01.15 |
---|---|
[C/C++] std::memcpy Api Reference (0) | 2016.10.21 |
[C/C++] vector api reference (0) | 2016.10.21 |
[C/C++] XOR 연산자 '^' (0) | 2016.10.20 |
[DBUS] DBUS 설명 사이트 정보 (0) | 2016.01.27 |