⚡高效地使用std::map

map<string, int>  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);
}

gcc version 12.2.0 (Debian 12.2.0-14+deb12u1) 不用加-std

image

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

posted @ 2025-11-08 14:41  华容道专家  阅读(3)  评论(0)    收藏  举报