I want to initialize a vector using the std::strings array .
I have the following solution, but wondered if there is a more elegant way to do 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 specifying the size as follows:
int size = ( sizeof ( str ) / sizeof ( std::string ) );
and replacing vector initialization with:
vec = vector< std::string >( str, str + size );
But it still seems a little "inelegant."
source
share