#include <bits/stdc++.h>
using namespace std;
int main()
{
vector<int> v(10, 0);
cout << "1: ";
for(int x : v) cout << x << ' '; cout << endl;
vector<int> v2(10);
v2.push_back(10);
cout << "2: ";
for(int x : v2) cout << x << ' '; cout << endl;
v.insert(v.begin(), 3);
v.insert(v.begin(), 2);
v.insert(v.begin(), 1);
cout << "3: ";
for(int x : v) cout << x << ' '; cout << endl;
v.pop_back();
cout << "4: ";
for(int x : v) cout << x << ' '; cout << endl;
v.erase(v.begin());
cout << "5: ";
for(int x : v) cout << x << ' '; cout << endl;
cout << "6: ";
auto iter = find(v.begin(), v.end(), 3);
if (iter != v.end()) {
int idx = distance(v.begin(), iter);
cout << "3 is v[" << idx << "]" << endl;
} else {
cout << "3 is not found." << endl;
}
cout << "7: ";
sort(v.begin(), v.end());
for(int x : v) cout << x << ' '; cout << endl;
cout << "8: ";
sort(v.rbegin(), v.rend());
for(int x : v) cout << x << ' '; cout << endl;
}
結果
1: 0 0 0 0 0 0 0 0 0 0
2: 0 0 0 0 0 0 0 0 0 0 10
3: 1 2 3 0 0 0 0 0 0 0 0 0 0
4: 1 2 3 0 0 0 0 0 0 0 0 0
5: 2 3 0 0 0 0 0 0 0 0 0
6: 3 is v[1]
7: 0 0 0 0 0 0 0 0 0 2 3
8: 3 2 0 0 0 0 0 0 0 0 0