fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. vector< vector< int > > MyFunc(int x_size, int y_size)
  6. {
  7. vector< vector< int > > array(y_size, vector< int >(x_size));
  8.  
  9. int i = 0;
  10. for (int y = 0; y < array.size(); y++)
  11. {
  12. for (int x = 0; x < array[y].size(); x++)
  13. {
  14. // note the order of the index
  15. array[y][x] = i++;
  16. }
  17. }
  18.  
  19. return array;
  20. }
  21.  
  22. int main()
  23. {
  24. vector< vector< int > > bob = MyFunc(10, 5);
  25. for (int y = 0; y < bob.size(); y++)
  26. {
  27. for (int x = 0; x < bob[y].size(); x++)
  28. {
  29. cout << bob[y][x] << "\n";
  30. }
  31. }
  32. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
0
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
41
42
43
44
45
46
47
48
49