在C ++ 0x中,我想要的是:
std::list<std::string> colours = {"red", "blue", "green", "grey", "pink", "violet"};
标准的非0x C ++中最简单的方法是什么?
答案 0 :(得分:11)
char const *x[] = {"red", "blue", "green", "grey", "pink", "violet"};
std::list<std::string> colours(x, x + sizeof(x) / sizeof(*x));
或者您可以使用增强库和list_of("a")("b")...