How to insert items into a set 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");

	set<string>::iterator p = st.begin();

	while (p != st.end()) {
		cout << *p << " ";
		p++;
	}
	cout << endl;

	return 0;
}


/*
run:

c c++ java php python

*/

 



answered Apr 23, 2018 by avibootz

Related questions

1 answer 168 views
1 answer 158 views
158 views asked Aug 4, 2018 by avibootz
1 answer 141 views
141 views asked Sep 18, 2022 by avibootz
1 answer 63 views
...