testhashmap.cpp

来自「C++高级编程这本书所附的源代码」· C++ 代码 · 共 39 行

CPP
39
字号
#include "hashmap.h"#include <iostream>using namespace std;int main(int argc, char** argv){  hashmap<int, int> myHash;  myHash.insert(make_pair(4, 40));  myHash.insert(make_pair(6, 60));  hashmap<int, int>::value_type* x = myHash.find(4);  if (x != NULL) {    cout << "4 maps to " << x->second << endl;  } else {    cout << "cannot find 4 in map\n";  }  myHash.erase(4);  hashmap<int, int>::value_type* x2 = myHash.find(4);  if (x2 != NULL) {     cout << "4 maps to " << x2->second << endl;  } else {    cout << "cannot find 4 in map\n";  }  myHash[4] = 35;  myHash[4] = 60;  hashmap<int, int>::value_type* x3 = myHash.find(4);  if (x3 != NULL) {     cout << "4 maps to " << x3->second << endl;  } else {    cout << "cannot find 4 in map\n";  }  return (0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?