I wish to initialise a vector using an array of std::string
s.
I have the following solution, but wondered if there's a more elegant way of doing this?
std::string str[] = { "one", "two", "three", "four" };
vector< std::string > vec;
vec = vector< std::string >( str, str + ( sizeof ( str ) / sizeof ( std::string ) ) );
I could, of course, make this more readable by defining the size as follows:
int size = ( sizeof ( str ) / sizeof ( std::string ) );
and replacing the vector initialisation with:
vec = vector< std::string >( str, str + size );
But this still feels a little "inelegant".