How to add element to C++ array?

后端 未结 11 2474
旧时难觅i
旧时难觅i 2020-12-12 23:26

I want to add an int into an array, but the problem is that I don\'t know what the index is now.

int[] arr = new int[15];
arr[0] = 1;
arr[1] = 2;
arr[2] = 3;         


        
11条回答
  •  孤城傲影
    2020-12-13 00:10

    You can use a variable to count places in the array, so when ever you add a new element, you put it in the right place. For example:

    int a = 0;
    int arr[5] = { };
    arr[a] = 6;
    a++;
    

提交回复
热议问题