cpp_playground/stl/map.cpp

17 lines
423 B
C++
Raw Permalink Normal View History

2022-10-17 23:48:04 +08:00
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
map<int, string> itos;
itos.insert({1, "abc"});
itos.insert({2, "def"});
itos.insert({3, "ghi"});
auto it = itos.find(2);
it = find_if(itos.begin(), itos.end(), [](pair<int, string> p) { return p.second.find("g") != string::npos; });
cout << it->first << ": " << it->second << endl;
}