1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
#include <fstream>
#include <iostream>
#include <string>
#include "Hash.hpp"

int main() {
   Hash<std::string, unsigned int> hash(32);
   std::string town; unsigned int population;
   std::ifstream cities("cities");
   while (cities >> town && cities >> population) {
      auto [it, ok] = hash.insert(std::make_pair(town, population));
      if (!ok) {
	 std::cerr << "insertion of " << town << " failed." << std::endl;
      }
   }
   while (std::cin >> town) {
      auto it = hash.find(town);
      if (it == hash.end()) {
	 std::cerr << town << " not found." << std::endl;
      } else {
	 // std::cout << it->second.population << std::endl;
	 std::cout << (*it).second << std::endl;
	 hash.erase(it);
      }
   }
   for (auto& object: hash) {
      std::cout << object.first << " " << object.second << std::endl;
   }
}