Skip to content

Instantly share code, notes, and snippets.

@poanchen
Created September 19, 2017 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save poanchen/58a116084a31973f0d169915c2cb9240 to your computer and use it in GitHub Desktop.
Save poanchen/58a116084a31973f0d169915c2cb9240 to your computer and use it in GitHub Desktop.
Create a std::map and insert into it the key-value pairs {“one”,1}, {“two”,2}, and {“three”,3}.
// https://repl.it/LO2s
#include <iostream>
#include <map>
using namespace std;
int main()
{
std:map <string, int> intMap;
intMap.insert(std::pair <string, int> ("one", 1));
intMap.insert(std::pair <string, int> ("two", 2));
intMap.insert(std::pair <string, int> ("three", 3));
std::map<string, int>::iterator it = intMap.begin();
cout << "intMap holds: \n";
for (it=intMap.begin(); it!=intMap.end(); ++it) {
std::cout << it->first << " => " << it->second << '\n';
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment