Need your help with vector

Hi everybody! i need somebody's help. I located 2d array into vector, but I don't how to "std::cout" it. Please, help.
Oh, and 1 more thing. If somebody know better way to locate 2d array into vector, I'll apreciate your help.

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cstdlib>
#include <vector>

#define COL 8
#define ROW 8

using namespace std;

void del(int**);

int main()
{
    int arr[COl][ROW];
    vector<int> mV;

    for(int i=0; i<COL; i++)
    {
        for(int j=0; j<ROW; j++)
            arr[i][j]=rand()%100;
    }

    int **p, **s, *h;
    p=new int*[COL];
    for(int i=0; i<COL; i++)
        p[i]=new int[ROW];
    
    s=new int*[COL];
    for(int i=0; i<COL; i++)
        s[i]=new int[ROW];
    
    for(int i=0; i<COL; i++)
    {
        for(int j=0; j<ROW; j++)
            p[i][j]=arr[i][j];
    }

    del(s);
    int q, w;
    for(q=0, s=p; q<COL; q++, s++)
    {
        for(w=0, h=*s; w<ROW; w++, h++)
            mV.push_back(*h);
    }

    for(q=0, s=p; q>COL; q++, s++)
    {
         for(w=0, h=*s; w<ROW; w++, h++)
              cout<<mV[*h]<<" ";
         cout<<endl;
     }

    del(p);
 
    return 0;
}

void del(int **p)
{
    for(int i=0; i<COL; i++)
        delete[] p[i];
    delete[] p;
}
Last edited on
in the same way you've populated the vector you could write a method to print it out in the same way.
I have tried to do it in way, like you said, but I failed. My compiler gave me a segmentation fault.
Could you show me some exapmle?
Last edited on
No need in example any more. I have done it by myself. But I have a new probelm. arr[COL][ROW] and vector content are different. Why???
Last edited on
Topic archived. No new replies allowed.