[C++] 進制轉換 Part 2
這次是把 etutor 的作業做延伸, 並且用 STL 中的 map 實作! 上一次是用 vector 來實作 延伸閱讀:C++ 進制轉換 map map 的概念就是 映射 由數個數對構成 數對是以 key : value 的形式存在 任一 key 可對到其 value 同一個 key 不會有不同 value ,像是 函數 定義 ※ 因為程式碼有高度重複性,所以就貼一部分而已 程式碼大概如下: 使用 map 建表 map<string, string> dicHex = { {"0", "0000"}, {"1", "0001"}, {"2", "0010"}, {"3", "0011"}, {"4", "0100"}, {"5", "0101"}, {"6", "0110"}, {"7", "0111"}, {"8", "1000"}, {"9", "1001"}, {"a", "1010"}, {"b", "1011"}, {"c", "1100"}, {"d", "1101"}, {"e", "1110"}, {"f", "1111"}, {"A", "1010"}, {"B", "1011"}, {"C", "1100"}, {"D", "1101"}, {"E", "1110"}, {"F", "1111"}, {"0000", "0"}, {"0001", "1"}, {"0010", "2"}, {"0011", "3"}, {"0100", "4"}, {"0101", "5"}, {"0110", "6"}, {"0111", "7"}, {"1000", "8"}, {"1001", "9"}, {"1010", "a"}, {"1011", "b"}, {"1100", "c"}, {"1101", "d"}, {"1110", "e"}, {"1111", "f"} }; 確認數字是否為有效的 (有 checkBin 、 checkOct 、 checkHex) bool checkBin(string number) { int length = number....