Blog Archive

Tuesday, July 2, 2019

How to initialize a string set in C++?

https://stackoverflow.com/questions/12333783/how-to-initialize-a-string-set-in-c

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]));

No comments:

Post a Comment