문제

In C++0x, what I want would be:

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

What's the easiest way in standard, non-0x C++?

도움이 되었습니까?

해결책

char const *x[] = {"red", "blue", "green", "grey", "pink", "violet"};
std::list<std::string> colours(x, x + sizeof(x) / sizeof(*x));

Or you can use the boost libraries and functions like list_of("a")("b")...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top