我很难返回一个字符串向量数组。我有一个功能:
std::vector<std::string>* generatecVec(std::vector<std::string> strVec){
std::vector<std::string> cVec[3];
cVec[0].push_back("Test11");
cVec[0].push_back("Test12");
cVec[0].push_back("Test13");
cVec[1].push_back("Test21");
cVec[1].push_back("Test22");
cVec[1].push_back("Test23");
cVec[2].push_back("Test31");
cVec[2].push_back("Test32");
cVec[2].push_back("Test33");
return cVec;
}
后来我使用了类似的功能
std::vector<std::string> *cVec = generatecVec(strVec);
for(std::vector<string>::iterator it = cVec[0].begin(); it != cVec[0].end(); ++it) {
std::cout << *it;
}
但我不断收到分段错误。我意识到我必须不正确地使用指针,但我该如何解决这个问题?我使用向量数组是因为它很容易通过索引来引用它(我只需要三个,非动态的)。谢谢!