I have a few words to be initialized while declaring a string set.
... using namespace std; set<string> str; /*str has to contain some names like "John", "Kelly", "Amanda", "Kim".*/
I don't want to use str.insert("Name"); each time.
str.insert("Name");
Any help would be appreciated.
Using C++11:
std::set<std::string> str = {"John", "Kelly", "Amanda", "Kim"};
Otherwise:
std::string tmp[] = {"John", "Kelly", "Amanda", "Kim"}; std::set<std::string> str(tmp, tmp + sizeof(tmp) / sizeof(tmp[0]));
2.1m questions
2.1m answers
60 comments
57.0k users