在C ++ 0x中,我想要的是:

std::list<std::string> colours = {"red", "blue", "green", "grey", "pink", "violet"};

标准,非0x C ++的最简单方法是什么?

有帮助吗?

解决方案

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

或者,您可以使用Boost库和功能 list_of("a")("b")...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top