dynamically change the size of an array c++

后端 未结 3 1015
逝去的感伤
逝去的感伤 2021-01-24 13:56

I have an array defined as;

static double Temp_data[TABLE_SIZE];

I want to change the size of the array according to the user input.

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-24 14:16

    Use dynamic memory allocation.

    int size;
    cin>>size
    int *ptr = new int[size];
    

    http://www.cplusplus.com/doc/tutorial/dynamic/

提交回复
热议问题