C++ vector of char array

后端 未结 7 874
梦谈多话
梦谈多话 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:48

    You can use boost::array to do that:

    boost::array test = {'a', 'b', 'c', 'd', 'e'};
    std::vector > v;
    v.push_back(test);
    

    Edit:

    Or you can use a vector of vectors as shown below:

    char test[] = {'a', 'b', 'c', 'd', 'e'};
    std::vector > v;
    v.push_back(std::vector(test, test + sizeof(test)/ sizeof(test[0])));
    

提交回复
热议问题