C++ STL 容器基本範例實驗測試[06_CPP_STL_Map ->純C++ Map範例 ]
資料來源:https://www.cnblogs.com/skyfsm/p/6934246.html
http://larry850806.github.io/2016/06/06/STL1/
http://larry850806.github.io/2016/06/06/STL2/
GITHUB 完整資料: https://github.com/jash-git/Base_CPP_STL_Example [ 包含免安裝開發環境:CodeBlocks 12.11 方便自己測試使用 ]
線上執行:https://www.tutorialspoint.com/compile_cpp_online.php / http://codepad.org/
Map 就像是一個對應表
只能拿走最上面的,或是繼續往上疊[先進後出]
基本功能有:
▲ []: 得到對應的值
▲ count: 檢查某個值是否有對應值
▲ size: 取個數
Map 的優點
▲ 設定對應值很簡單
▲ 用很高的效率找到對應值
Map 的缺點
▲ 對應值越多會越慢
本範例額外紀錄
▲ string 對應到 string 當沒有值會顯示空白
▲ string 對應到 int 當沒有值會顯示 0
#include#include #include /* malloc, free, rand */ #include /*strncpy .....*/ #include /*c++ string class*/ #include #include #include #include #include