C++ concatenate two int arrays into one larger array

前端 未结 6 2140
小蘑菇
小蘑菇 2020-12-08 16:20

Is there a way to take two int arrays in C++

int * arr1;
int * arr2;
//pretend that in the lines below, we fill these two arrays with different
//int values
         


        
6条回答
  •  孤街浪徒
    2020-12-08 16:46

    int * result = new int[size1 + size2];
    std::copy(arr1, arr1 + size1, result);
    std::copy(arr2, arr2 + size2, result + size1);
    

    Just suggestion, vector will do better as a dynamic array rather than pointer

提交回复
热议问题