我正在爲學校進行任務,我們需要在不使用矢量的情況下動態增加數組的大小。 這是我有,但它不斷清除這兩個列表。在C++中增加數組的大小而不使用矢量
string name;
int numOfClasses = 1;
string *listOfCourses = new string[numOfClasses];
string studentclasses;
void addToList(string n,int i) {
numOfClasses++;
string *copyOfListOfCourses = new string[numOfClasses];
memcpy(copyOfListOfCourses, listOfCourses, numOfClasses + 1);
copyOfListOfCourses[i] = n;
delete[] listOfCourses;
listOfCourses = copyOfListOfCourses;
}
你不能。C++中的數組是靜態大小的。 –
必須要離開,否則我們將不會被賦予做任務 –
@EliSadoff OP在哪裏使用_statically sizes arrays_?請解釋? –