轻松初始化std :: std :: strings的列表?
-
03-10-2019 - |
题
在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")...
不隶属于 StackOverflow