How to create, initialize and print unordered set in C++

1 Answer

0 votes
#include <iostream>  
#include <unordered_set>

using std::unordered_set;
using std::cout;
using std::endl;


void print(const unordered_set<int>& usset)
{
	for (const auto& element : usset) {
		cout << element << endl;
	}
	std::cout << std::endl;
}

int main()
{
	unordered_set<int> usset = { 7, 2, 8, 99, 18 };

	print(usset);

	return 0;
}

/*
run:

7
18
2
8
99

*/

 



answered Jan 12, 2018 by avibootz
edited Jan 15, 2018 by avibootz

Related questions

1 answer 193 views
1 answer 112 views
112 views asked Apr 7, 2020 by avibootz
1 answer 178 views
1 answer 172 views
...