5

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

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

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

4

1 回答 1

11
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")...

于 2010-09-16T12:25:13.933 回答