#include <iostream> #include <string> #include <map> using namespace std;typedef map<string, int> M; M m; const char K[] = "key";void fn1 () {auto p = m.insert({K, 0}); ++(p.first->second); }void fn2 () {auto it = m.find(K);if (it != m.end()) ++(it->second); }int main (int argc, char** argv) {if (argc == 1) fn1(); else fn2();cout << m[K] << '\n'; }
gcc version 12.2.0 (Debian 12.2.0-14+deb12u1) 不用加-std

加了-std=c++03可以编译通不过。:-)