Vector content to 2D array

Hello to everyone

Beginner in c++. I have I little problem. I would like to copy content of vector (vector<int> vrsta_2) into 2D array(int tabela[][]). What I got is this:
6729000
11215000
17944000
20187
I would like this:
6729000
1121500
0179440
0020187

Thank you very much for your help.

1
2
3
4
5
6
7
8
9
10
11
12
13
for(u=0;u<niz2.size();u++)//niz.2 is vector
{
    for(v=0;v<temp1;v++)//temp1 is a size of particular vector
    {
        tabela[u][v]=vrsta_2[p++];
        if(p==vrsta_2.size()+1)
        {
            break;
        }
        cout<<tabela[u][v];
    }
    cout<<endl;
}
Here is a way to do it
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
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <vector>

using namespace std;

const int ROW_COUNT = 3;
const int COL_COUNT = 3;

int numbers[ROW_COUNT][COL_COUNT] = { 0 };

vector<int> vNumbers (ROW_COUNT * COL_COUNT);

int main ()
{
  for (int i = 0; i < vNumbers.size (); ++i)
  {
    vNumbers[i] = i + 1;
  }

  for (int i = 0; i < vNumbers.size (); ++i)
  {
    int row = i / ROW_COUNT;
    int col = i % COL_COUNT;
    numbers[row][col] = vNumbers[i];
  }

  for (int row = 0; row < ROW_COUNT; ++row)
  {
    for (int col = 0; col < COL_COUNT; ++col)
    {
      cout << numbers[row][col] << " ";
    }
    cout << "\n";
  }


  system ("pause");
  return 0;
}
Thank you. I got it.
Topic archived. No new replies allowed.