I'm teaching myself C++ and getting a segmentation fault with my latest small prog. The fault occurs within the following function, at the "std::cin" statement.
- Code: Select all
void getValues(int** theMatrix, int& theRows, int& theColumns)
for (int row = 0; row < theRows; ++row)
// prompt for values
std::cout << std::endl << "Enter values for row " << (row + 1) << std::endl;
// and then use a for loop to assign values from cin
for (int column = 0; column < theColumns; ++column)
std::cin >> theMatrix[row][column];
The intention of this function is to prompt for and read integer values into a 2D array.
Could someone please explain why I'm getting this fault as everything seems OK to me.
Thanks in advance,