Map
Example 1
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, string> provinces = { {"ON","Ontario"},{"BC","British Columbia" },{"QC","Quebec" }};
cout << "Size of the map is " << provinces.size() << endl;
for (auto&&
p : provinces)
{
cout << p.first << "\t" << p.second <<endl;
}
system("pause");
return 0;
}
Example 2
#include <iostream>
//#include
<vector>
//#include
<list>
//#include
<set>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, string> famouspersons = { { "will","smith" },{ "john","tory" },{ "barack","obama" } };
cout << famouspersons["will"] << endl;
cout << famouspersons["john"] << endl;
cout << famouspersons["barack"] << endl;
map<string, string>::iterator it = famouspersons.begin();
for (; it !=
famouspersons.end(); it++)
{
cout << it->first << " :: " << it->second << endl;
}
system("pause");
return 0;
}
Comments
Post a Comment