开发者

Easily initialise an std::list of std::strings?

开发者 https://www.devze.com 2023-01-16 04:49 出处:网络
In C++0x, what I want would be: std::list<std::string> co开发者_如何学Golours = {\"red\", \"blue\", \"green\", \"grey\", \"pink\", \"violet\"};

In C++0x, what I want would be:

std::list<std::string> co开发者_如何学Golours = {"red", "blue", "green", "grey", "pink", "violet"};

What's the easiest way in standard, non-0x C++?


char const *x[] = {"red", "blue", "green", "grey", "pink", "violet"};
std::list<std::string> colours(x, x + sizeof(x) / sizeof(*x));

Or you can use the boost libraries and functions like list_of("a")("b")...

0

精彩评论

暂无评论...
验证码 换一张
取 消