Intializing C++ Containers

Tom Browder
Wed Jun 11 13:52:00 GMT 2003

In C++ we can initialize a char* vector (array) like so:

  char* vec[] = { "s1", "s2" };

Is there any equivalent way to do it for a C++ vector?  I don't think
so--except by constructing a std::vector<std::string> from the char* array
at runtime.

So the question is: wouldn't that be a "good thing" for a C++ extension to
g++?  It would continue the move away from the "dangerous" C string and it
would conserve space since we wouldn't need two copies of the array (or does
g++ do some behind-the-scenes optimizations?).  My idea of such an
initialization is:

  std::vector<std::string> vec = { "s1, "s2 };


Tom Browder

More information about the Gcc-help mailing list