2 dimensional string with random parameters question

Hi guys

Is there a way to declare and initiate a 2 dimensional string array using variables that will be random upon each run?

The issue is that the variables will be different with each run and from what I am seeing, there is not a direct way to do this. I do have an insane workaround that I am looking in to but it would be horribly inefficient and a TON of work.

Any ideas?
Why don't you create a function that creates a random string and fill your array with it each run?
@Thomas1965 a string certainly can hold my values but the issue is that it MUST be 2 dimensional. The issue specifically is getting the dimensions of the array for it each run. Every run the dimensions will be different so I can not use a static value, I have to use variables.

For a situation like that is there an alternative to a 2d string array that I am just not aware of? And thank you again Thomas. That other issue you solved was very helpful.
For your array, one option would be a vector of vector of string so you can resize it at each run.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
int main()
{
  typedef vector<string> DataRow;
  typedef vector<DataRow> array2D;

  int rowCount = 5;
  int colCount = 5;

  // create array2D
  array2D board(5);
  for (int row = 0; row < rowCount; row++)
    board[row].resize(colCount);

  // fill array2D
  for (int row = 0; row < rowCount; row++)
    for (int col = 0; col < colCount; col++)
      board[row][col] = "value " + to_string(row) + " " + to_string(col);

  // display array2D
  for (int row = 0; row < rowCount; row++)
  {
    for (int col = 0; col < colCount; col++)
      cout << board[row][col] << " ";

    cout << "\n";
  }
      

  system("pause");
  return 0;
}
Topic archived. No new replies allowed.