How to elegantly initialize vector<char *> with string literal?
问题 The problem comes from an exercise on C++ Primer 5th Edition: Write a program to assign the elements from a list of char* pointers to C-style character strings to a vector of strings. ----------------Oringinal Question------------ First I try the following somewhat direct way: vector<char *> vec = {"Hello", "World"}; vec[0][0] = 'h'; But compiling the code I get a warning: temp.cpp:11:43: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings] vector<char *> vec = {