The canonical way is to define begin()
and end()
functions in a suitable header and use something like this:
char const* array[] = {
"this is a",
"list of strings",
"which are going",
"to be stored",
"in a vector"
};
std::vector<std::string> vec(begin(array), end(array));
The functions begin()
and end()
are defined like this:
template <typename T, int Size>
T* begin(T (&array)[Size]) {
return array;
}
template <typename T, int Size>
T* end(T (&array)[Size]) {
return array + Size;
}