删除区间
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, a[20];
int main() {
// vector<int> v;
// cin >> n;
// for (int i = 0; i < n; i++) {
// cin >> a[i];
// v.push_back(a[i]);
// }
vector<int> v{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
for (auto x : v) {
cout << x << " ";
}
v.erase(v.begin() + 2, v.begin() + 5); // 删除在[2,5)间的元素(第2,3,4号元素)
puts("");
for (auto x : v) {
cout << x << " ";
}
return 0;
}
https://www.acwing.com/blog/content/6854/
数组和vector
https://www.cnblogs.com/love-yh/p/7410666.html
https://blog.csdn.net/zxyhhjs2017/article/details/92826730
c++ 将vector转化为数组
https://www.coonote.com/cplusplus-note/vector-to-array.html
https://www.jb51.net/article/224671.htm
C++ 数组转换vector
int arr[] = {1, 2, 3, 4, 5};
vector<int> v(arr, arr+5);
for (auto i : v) {
cout << i << ' ';
}
cout << endl;