轻松初始化std :: std :: strings的列表?

时间:2010-09-16 12:22:15

标签: c++ initialization stdstring stdlist

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

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

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

1 个答案:

答案 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")...

等功能