Type: Note
Content
前置
#include "stdafx.h" #include <string> #include <map> using namespace std;
宣告
int _tmain(int argc, _TCHAR* argv[]) { map<string, int> maps;Insert
map<string,int>::iterator it = maps.begin(); maps.insert(it, pair<string,int>("A",26)); maps.insert(it, pair<string,int>("B",27)); maps.insert(it, pair<string,int>("C",28)); maps.insert(it, pair<string,int>("D",29)); maps["E"] = 30;For Loop
for (it=maps.begin(); it != maps.end(); ++it){ printf("%s = %i\n", it->first.c_str(), it->second); }Get
printf("E = %i\n", maps["E"]); printf("F = %i\n", maps["F"]);//預設為0Remove
maps.erase("E");Find
it = maps.find("E"); if(it == maps.end()) printf("not found.\n"); else printf("%s = %i\n", it->first.c_str(), it->second);The end...
getchar(); return 0; }
沒有留言:
張貼留言