How to initialize a string set in C++?

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.

Any help would be appreciated.

Answers


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

Need Your Help

How to put binding information into a Resource

wpf xaml data-binding resourcedictionary

I was experimenting with using App.Config Properties.Settings in XAML. For instance I added a setting for GridMaxWidth as an int of 500. Then in my XAML I added

Why embed lua into a game engine?

scripting lua embed

I've been looking into building a basic game engine from the ground up and after making a list of features that are common to other engines, one of the bigger things is the fact that they have an

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.