How to get size of dynamic array in C++ [duplicate]
问题 This question already has an answer here: How to get size c++ dynamic array 3 answers Code for dynamic array by entering size and storing it into \"n\" variable, but I want to get the array length from a template method and not using \"n\". int* a = NULL; // Pointer to int, initialize to nothing. int n; // Size needed for array cin >> n; // Read in the size a = new int[n]; // Allocate n ints and save ptr in a. for (int i=0; i<n; i++) { a[i] = 0; // Initialize all elements to zero. } . . . //