How to insert and print pairs into a map of strings in c++

1 Answer

0 votes
#include <iostream>
#include <string>
#include <map>

using std::string;

int main() 
{
	std::map<string, string> prog;

	prog.insert(std::pair<string, string>("Ethan", "C++"));
	prog.insert(std::pair<string, string>("Tom", "C"));
	prog.insert(std::pair<string, string>("Liam", "Python"));

	auto itr = prog.begin();
	while (itr != prog.end())
	{
		std::cout << itr->first << " - " << itr->second << std::endl;
		itr++;
	}

	return 0;
}

/*
run:

Ethan - C++
Liam - Python
Tom - C

*/

 



answered Feb 15, 2018 by avibootz

Related questions

3 answers 162 views
3 answers 172 views
2 answers 182 views
182 views asked Apr 13, 2020 by avibootz
1 answer 202 views
1 answer 614 views
...