Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vector with two dimensions.

Status
Not open for further replies.

smail77

Programmer
Aug 17, 2000
9
MA
For create and using a vector (a dynamique table)we can use:

#include <vector>
using namespace std ;

vector<int> tableau;//a table of int for instance

void main()
{
tableau.push_back(5); //tu insére 5 dans le tableau
swap...
}

But how can create and using a vector which had two dimensions like we do with a static table
( int tab[10][12];)

Thanks.
 
The best way is to use structures:
struct tab
{
int x[10];
};
vector<tab> x;
tab a;
x.push_back(a);
or
struct tab
{
private:
int* x;
public:
tab(int numrows){x=new int[numcols];}
~tab{delete[] x;}
operator=(tab& a)
{..copy data from a to this struct..}
//for good copying you should overload operator=
}
vector<tab> x;
...blablabla; John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top