Problem with vectors

P

piruk

I create two dimensional vector:

vector < vector< vector<int> > > v(100);

And next I create
vector <int> temp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2

piruk
 
P

peter koch

I create two dimensional vector:

vector < vector< vector<int> > > v(100);

Thats three dimensions
And next I create
vector <int> temp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2

v[0][0] = temp;
will do fine.

/Peter
 
V

Victor Bazarov

piruk said:
I create two dimensional vector:

vector < vector< vector<int> > > v(100);

Actually that's a three-dimensional one. Did you mean to have one
less 'vector' in there?
And next I create
vector <int> temp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?

If your 'v' is actually two-dimensional, you just assign it
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2

You can't have a vector of 'int' "on index 0" in a vector of vectors
of vectors of int. You have to define 'v' as

vector<vector<int> > v(100);

then you can do

vector<int> temp(2);
temp[0] = 1;
temp[1] = 2;
v[0] = temp;
assert(v[0][0] == 1 && v[0][1] == 2);

V
 
V

Victor Bazarov

peter said:
I create two dimensional vector:

vector < vector< vector<int> > > v(100);

Thats three dimensions
And next I create
vector <int> temp(2);
temp[0]=1;
temp[1]=2;

And how to add temp to v on specified index?
For example I wold like to have vector temp on index 0 in v.
It means I would like to have:
v[0][0][0]=1 and v[0][0][1]=2

v[0][0] = temp;
will do fine.

No, it won't. v[0] has no element with the index 0. He can only
do

v[0].push_back(temp);

with the current declaration of 'v'.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,197
Messages
2,571,038
Members
47,633
Latest member
BriannaLyk

Latest Threads

Top