Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,938 questions

51,875 answers

573 users

How to initialize an unordered_map through a range of other unordered_map in C++

1 Answer

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

using std::string;
using std::cout;
using std::endl;

int main() 
{
	std::unordered_map<string, int> workers({{ "Liam ", 45}, { "Logan", 37}, { "Ethan", 51}});

	std::unordered_map<std::string, int> w2(workers.begin(), workers.end());

	for (std::pair<std::string, int> element : w2)
		cout << element.first << " - " << element.second << endl;

	return 0;
}

/*
run:

Liam  - 45
Logan - 37
Ethan - 51

*/

 



answered Feb 15, 2018 by avibootz

Related questions

3 answers 243 views
243 views asked Feb 20, 2019 by avibootz
1 answer 142 views
1 answer 120 views
2 answers 133 views
1 answer 114 views
114 views asked Sep 17, 2022 by avibootz
2 answers 1,675 views
3 answers 290 views
...