📅  最后修改于: 2022-03-11 14:44:57.199000             🧑  作者: Mango
// Heap allocated array in c++
//using std::vector
#include
std::vector bestArray(100); //A vector is a dynamic array, which (by default) allocates elements from the heap
//or managing memory yourself
myarray* heapArray = new myarray[100];
delete [] heapArray; // when you're done
//How to use vector to put elements inside the array.
// C++11:
std::vector bestArray{ 1, 2, 3 };
// C++03:
std::vector bestArray;
bestArray.push_back(myarray(1));
bestArray.push_back(myarray(2));
bestArray.push_back(myarray(3));