CArrayarr; arr.Add(10); arr.Add(20); int* data = arr.GetData(); for(int i = 0; i < arr.GetSize(); i++) { std::cout << data[i] << " "; } // Output: 10 20
#includeIn this example, we create an integer array and initialize it with some values. We then create a CArray object and append the integer array to it using the Append() method. We use the GetData() method to get a pointer to the first element of the CArray object and print the value at index 2. Overall, the CArray class template and the GetData() method are part of the MFC library in C++. These features are used for managing dynamic arrays and getting direct access to their data.#include int main() { int data[] = {10, 20, 30, 40}; CArray arr; arr.Append(data, 4); int* ptr = arr.GetData(); std::cout << ptr[2] << '\n'; } // Output: 30