在 C++0x 中,我想要的是:
std::list<std::string> colours = {"red", "blue", "green", "grey", "pink", "violet"};
标准的非 0x C++ 中最简单的方法是什么?
在 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")...