---
# System prepended metadata

title: map

---

# map
map就像是python的dict，map就像一個對照表，一個key對上一個value，可以用中括號[]來得到對應的值，map也可以使用count()檢查某個值是否有對應值。
```cpp=
#include <iostream>
#include <map>
using namespace std;
int main(){
    map<int,string> m;
    m[1] = "one";
    m[2] = "two";
    m[3] = "three";
    m[4] = "four";
    cout << m.count(1) << endl;//存在輸出1
    cout << m.count(5) << endl;//存在輸出0
    
    cout << m[2] << endl;//output = two
    cout << m[3] << endl;//output = three 
    
    return 0;
}
```