void RemoveFirstIndex(std::vector<std::string> &inArray) {
if (!inArray.empty())
inArray.erase(inArray.begin());
}
std::vector<std::string> array = {"Hello", "How", "Are"};
RemoveFirstIndex(inArray)
// array now contains {"How", "Are"}
您不应该使用 char 指针数组,但如果需要,您需要指明它的大小以及函数随后指明新大小的方法。
size_t RemoveFirstIndex(char **inArray, size_t n) {
if (n==0)
return n;
std::rotate(inArray,inArray+1,inArray+n);
// raw pointers indicate we don't own these resources
// so we don't need to deallocate anything...
return n-1;
}
char *array[] = {"Hello", "How", "Are"};
size_t size = sizeof array/sizeof *array;
for (size_t i=0;i<size;++i)
std::cout << array[i] << '\n';
size = RemoveFirstIndex(array,size);
for (size_t i=0;i<size;++i)
std::cout << array[i] << '\n';