C++ vector of char array

后端 未结 7 900
梦谈多话
梦谈多话 2020-12-09 16:06

I am trying to write a program that has a vector of char arrays and am have some problems.

char test [] = { \'a\', \'b\', \'c\', \'d\', \'e\' };

vector

        
7条回答
  •  温柔的废话
    2020-12-09 16:56

    What I found out is that it's OK to put char* into a std::vector:

    //  1 - A std::vector of char*, more preper way is to use a std::vector> or std::vector
    std::vector v(10, "hi!");    //  You cannot put standard library containers e.g. char[] into std::vector!
    for (auto& i : v)
    {
        //std::cout << i << std::endl;
        i = "New";
    }
    for (auto i : v)
    {
        std::cout << i << std::endl;
    }
    

提交回复
热议问题