If you are more interested in an elegant solution, you can try VectorEx from here: https://github.com/gileli121/VectorEx
In VectorEx.h, you have already created a 2D array data structure that you can easily use (e.g. std :: vector). This solution was implemented at a low level: std::vector<std::vector<DataType>>
From your point of view, you see this as vectorex::vector2d<DataType> aArray
Then to build a 2d array, for example, with 100 rows and 100 columns, you do aArray.build(100, 100); . He will build an array.
The second important advantage is a function that can display a 2d array as you open microsoft excel and display the array in it.
Function vectordisplay::DisplayVector_2d in VectorDisplay.h
This function will work under windows. tested on Windows 7 64 bit.
Please note that this project is new and errors are possible. function names may change over time.
Here are examples of how to use it:
// includes.functions

Example 2:
// includes.functions #include <windows.h> // Include CU3 Library // Get the files from https://github.com/gileli121/CU3-Library/

Example 3:
int main() { vector2d<std::string> aTest; // Declare the 2D array aTest.build(10, 5); // build the 2D array DisplayVector_2d(&aTest); // Show aTest.resize(100, 100); // Resize DisplayVector_2d(&aTest); // Show aTest.overwrite("AAA"); // Write "AAA" on all the array DisplayVector_2d(&aTest); // Show aTest.resize(50, 50); // Resize DisplayVector_2d(&aTest); // Show aTest.resize(100, 100); // Resize DisplayVector_2d(&aTest); // Show aTest.unbuild(); /* Free memory *Don't use the array after unbuild. to use again, you need to build() it again!*/ vector2d<int> aTest2; // Declare the 2D array of ints aTest2.build(100, 100); DisplayVector_2d(&aTest2); // Show aTest2.overwrite(100, 10, 5, 60, 30); /* Write the value 100 on rows 10-60, and on cols 5-30 */ DisplayVector_2d(&aTest2); // Show return 0; }
Hope you found this helpful.
For more information and an example, go to https://github.com/gileli121/VectorEx and <a4>
NOTE: initialize() changed to build() . Ignore "initialize" on images