This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Intializing C++ Containers
- From: "Tom Browder" <tom3 at fwb dot asi dot srs dot com>
- To: <gcc-help at gcc dot gnu dot org>
- Date: Wed, 11 Jun 2003 08:58:06 -0500
- Subject: Intializing C++ Containers
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 };
Thanks.
Tom Browder