#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<random>
#include<chrono>
using namespace std;
unsigned a[] = {
11,12,13,14,15,16,17,18,19,20 };
map<unsigned, unsigned> m; vector<unsigned> v;
mt19937_64 re;
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); re.seed(chrono::steady_clock::now().time_since_epoch().count());
for (auto i : a) {
m.emplace(make_pair(i, i)); v.emplace_back(i);
}
shuffle(a, a + 10, re);
for (auto i : a) {
auto j = m.erase(m.find(i));
cout << "(j == m.end) == " << boolalpha << (j == m.end()) << endl;
cout << "m.crbegin()->first == " << m.crbegin()->first << endl;
cout << "Erased term = " << i << ", m.size = " << m.size() << ", following term = " << j->first << endl;
cout << endl;
}
cout << endl;
for (auto i : a) {
auto j = v.erase(find(v.cbegin(), v.cend(), i));
cout << "(j == v.end) == " << boolalpha << (j == v.end()) << endl;
cout <<
【C++】map::erase 与 vector::erase 的返回值
最新推荐文章于 2025-04-08 00:00:00 发布