//Using a Map in C++
// By Ben 20:29 26/09/2018

#include <iostream>
#include <map>
#include <iterator>
using namespace std;

int main(){

	map<int, string>Names;
	map<int, string>::iterator ir;

	//Store ID and name
	Names.insert(pair<int, string>(1, "Ben"));
	Names.insert(pair<int, string>(2, "Ted"));
	Names.insert(pair<int, string>(3, "Paul"));
	Names.insert(pair<int, string>(4, "David"));
	Names.insert(pair<int, string>(5, "Josh"));

	//Add headers
	std::cout << "ID\tName" << endl;

	//Print out the ID and names in the map
	for (ir = Names.begin(); ir != Names.end(); ir++){
		cout << ir->first << "\t" << ir->second.c_str() << endl;
	}

	std::cout << "Size: " << Names.size() << endl;

	//Copy Names to Names2
	map<int, string>Names2(Names.begin(), Names.end());

	//Clear Names
	Names.clear();

	//Delete some items
	Names2.erase(3); // Delete Paul
	Names2.erase(2); // Delete Ted
	
	//Swap items 1 and 5
	string temp;
	temp = Names2[5];
	Names2[5] = Names2[1];
	Names2[1] = temp;

	//Change David to Dave
	Names2[4] = "Dave";

	//Add headers
	std::cout << "\nID\tName" << endl;

	//Print out the ID and names in the map
	for (ir = Names2.begin(); ir != Names2.end(); ir++){
		cout << ir->first << "\t" << ir->second.c_str() << endl;
	}
	std::cout << "Size: " << Names2.size() << endl;
	system("pause");
	return 0;
}