How to print set with for loop in C++

1 Answer

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

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

int main()
{
	set<string> st;

	st.insert("c++");
	st.insert("c");
	st.insert("java");
	st.insert("php");
	st.insert("python");

	typedef set<string>::const_iterator ci;
	for (ci it = st.begin(); it != st.end(); it++)
		cout << *it << " ";
	cout << endl;

	return 0;
}


/*
run:

c c++ java php python

*/

 



answered Apr 23, 2018 by avibootz

Related questions

2 answers 314 views
1 answer 121 views
121 views asked Mar 14, 2024 by avibootz
1 answer 151 views
1 answer 184 views
184 views asked Jun 14, 2020 by avibootz
2 answers 230 views
230 views asked Apr 24, 2018 by avibootz
1 answer 322 views
...