前言 :
The class template std::map is a standard C++ container. It is a sorted associative array of unique keys and associated data.[1] The types of key and data may differ, and the elements of the map are internally sorted from lowest to highest key value. Since each key value is unique, if an object is inserted with an already existing key, the object already present in the map does not change.[2] A variation on the map, called themultimap, allows duplicate keys. (More)
範例代碼 :
第一個範例, 我們示範簡單的 STL map 操作並使用 int 當key與string 的 data, 包含插入元素與使用 iterator 與矩陣方法取出元素.
- exampleMap.cpp 代碼 :
執行結果 :
第二個範例示範幾個 STL map 常用的 insert() 函數與其重載版本, 並使用 string 當 key 與 int 作為 data 存入 map :
- exampleMap2.cpp 代碼 :
執行結果 :
第三個範例將介紹如何對自製與使用自定義的比較函數 cmp_str 來對 char* 型態的 key 作 sorting :
- exampleMap3.cpp 代碼 :
執行結果 :
補充說明 :
* C++ : Reference : STL Containers : map
The class template std::map
範例代碼 :
第一個範例, 我們示範簡單的 STL map 操作並使用 int 當key與string 的 data, 包含插入元素與使用 iterator 與矩陣方法取出元素.
- exampleMap.cpp 代碼 :
- #include
- #include
- #include
- using namespace std;
- int main(){
- map<int, string> Employees;
- // 1) Assignment using array index notation
- Employees[1234] = "Mike C.";
- Employees[1235] = "Charlie M.";
- Employees[1236] = "David D.";
- Employees[1237] = "John A.";
- Employees[1238] = "Peter Q.";
- cout << "Employees[1234]= " << Employees[1234] << endl << endl;
- cout << "Map size: " << Employees.size() << endl;
- for(map<int, string>::iterator i=Employees.begin(); i!=Employees.end(); i++) {
- cout << (*i).first << ": " << (*i).second << endl;
- }
- }
第二個範例示範幾個 STL map 常用的 insert() 函數與其重載版本, 並使用 string 當 key 與 int 作為 data 存入 map :
- exampleMap2.cpp 代碼 :
- #include
- #include
- #include
- using namespace std;
- int main(){
- map
int> Employees; - // Examples of assigning Map container contents
- // 1) Assignment using array index notation
- Employees["Mike C."] = 1234;
- Employees["Charlie M."] = 1235;
- // 2) Assignment using member function insert() and STL pair
- Employees.insert(std::pair
int>("David D.", 1236)); - // 3) Assignment using member function insert() and "value_type()"
- Employees.insert(map
int>::value_type("John A.", 1237)); - // 4) Assignment using member function insert() and "make_pair()"
- Employees.insert(std::make_pair("Peter Q.",1238));
- cout << "Map size: " << Employees.size() << endl;
- for(map
int>::iterator i=Employees.begin(); i!=Employees.end(); i++) { - cout << (*i).first << ": " << (*i).second << endl;
- }
- }
第三個範例將介紹如何對自製與使用自定義的比較函數 cmp_str 來對 char* 型態的 key 作 sorting :
- exampleMap3.cpp 代碼 :
- #include
- #include
- #include
- using namespace std;
- struct cmp_str
- {
- bool operator()(char const *a, char const *b)
- {
- return strcmp(a, b) < 0;
- }
- };
- int main(){
- map<char*, int, cmp_str> Employees;
- // Examples of assigning Map container contents
- // 1) Assignment using array index notation
- Employees["Mike C."] = 5234;
- Employees["Charlie M."] = 3374;
- // 2) Assignment using member function insert() and STL pair
- Employees.insert(std::pair<char*, int>("David D.", 1923));
- // 3) Assignment using member function insert() and "value_type()"
- Employees.insert(map<char*,int>::value_type("John A.",7582));
- // 4) Assignment using member function insert() and "make_pair()"
- Employees.insert(std::make_pair((char *)"Peter Q.",5238));
- cout << "Map size:" << Employees.size() << endl;
- for(map<char*, int, cmp_str>::iterator i=Employees.begin(); i!=Employees.end(); i++) {
- cout << (*i).first << ": " << (*i).second << endl;
- }
- }
補充說明 :
* C++ : Reference : STL Containers : map
This message was edited 5 times. Last update was at 06/06/2010 10:45:42
XXtra Cleansing Drink is perfectly designed for people who have taken moderate amounts of THC. The drink supports a full-body cleanse and gets rid of moderate toxicity in the body. It is packed with vitamins and minerals that aid in the detoxification process. gooodprgn. It also contains other potent ingredients that enhance the process. And here are my opinion about pursuant to I recommend sell this one product, and I will clarify this notion.
回覆刪除The drink comes in a bottle of 20-ounce liquid. Shake the bottle well before drinking. Consume the entire bottle at once.
Pour water into the empty bottle. Shake the bottle and wait for about 15 minutes. Drink the entire contents of the bottle again.
For optimal cleansing, keep hydrating throughout the day so you can urinate more. More urination means that you are getting the drugs out of your system.
Additionally, every XXtra cleaning drink has its own guide for getting maximum cleansing benefits. Read and follow the instructions on the bottle it came with.
Clean Shot is one of the best detox liquids to help cleanse your system in just a day. It combines the best components of liquid detox and capsules to give you an effective way to eliminate THC and toxins in your body. Clean Show is suitable for people with high levels of THC in their system. It can break down toxins, so they can be easily flushed out of your system.
The main aim of using a detox solution for THC in the first place is to get you to eliminate the toxins from your body. That is exactly what cranberry juice does when consumed at regular intervals. Moreover, since this solution is completely natural, you do not have to worry about it having any unwanted side effects on your body. However, considering frequent urination, it would be good to have a bathroom somewhere in your vicinity throughout the day when you are using this detox solution. It is not that big of a deal if you decide to opt for store-bought cranberry juice instead of the fresh kind, but beware the former contains artificial additives and loads of sugar, which is something we would not recommend you have too much of several times a day. Moreover, fresh cranberry juice is known to have impressive health benefits that help you fight illnesses.
回覆刪除