Skip to content
Rain Hu's Workspace
Go back

[C++] The C++ Standard Template Library(STL) - map

Rain Hu

map

宣告

map <int, int> mp; // key和value都是整數

方法

mp[key] = value;

mp.count(key);

mp.erase(key);

mp.clear();

value = mp[key]

mp.empty()

map 的遍歷

for (auto it = mp.begin(); it != mp.end(); ++it){
    cout << it->first << " => " << it->second << '\n';
}
 
for (auto it = mp.begin(); it != mp.end(); ++it){
    cout << (*it).first << " => " << (*it).second << '\n';
}

Share this post on:

Previous
[IT] Introduction to Microservices, Docker and Kubernetes
Next
[Java] HashMap中的hashCode設計原理