How to dynamically increase the array size?

前端 未结 3 1265
一向
一向 2021-02-03 12:01

I\'ve been trying to make a program that adds 2 arrays of different size. But I would like to know to to dynamically increase the array size capacity? Ex: array[4] then upgrade

3条回答
  •  名媛妹妹
    2021-02-03 12:34

       int* newArr = new int[new_size];
       std::copy(oldArr, oldArr + std::min(old_size, new_size), newArr);
       delete[] oldArr;
       oldArr = newArr;
    

提交回复
热议问题