I wrote this program and ran it. It didn't print out all the rows, just 3. While I was debugging, I saw that the debug process was stopped. I still have no idea why this happened.
#include <iostream>
#include <vector>
#include <chrono> // for system_clock
#include <random> // for random number engines and distributions
int main()
{
// obtain a seed from the system clock
unsigned seed = static_cast<int> (std::chrono::system_clock::now().time_since_epoch().count());
// seeds the random number engine, the default random engine
std::default_random_engine gen(seed);
// set a distribution range (1 - 100)
std::uniform_int_distribution<int> dist(1, 100);
// get the number of rows from the user
std::cout << "The number of rows: ";
int rows;
std::cin >> rows;
// get the number of columns from the user
std::cout << "The number of columns: ";
int columns;
std::cin >> columns;
std::cout << "\n";
// create the 2-dimensional vector (int) from the supplied values
std::vector< std::vector<int> > vec(rows, std::vector<int>(columns));
// fill the vector with some random values
for (int row_loop = 0; row_loop < rows; row_loop++)
{
for (int col_loop = 0; col_loop < columns; col_loop++)
{
vec[row_loop][col_loop] = dist(gen);
}
}
// display the contents of the vector
for (int row_loop = 0; row_loop < rows; row_loop++)
{
for (int col_loop = 0; col_loop < columns; col_loop++)
{
std::cout << vec[row_loop][col_loop] << "\t";
}
std::cout << "\n";
}
}
The number of rows: 3
The number of columns: 5
83 72 18 86 34
73 63 37 81 52
97 39 22 12 4