vector of vector's

T

thomas

Hi, a question about vectors

----code---
vector<vector<int> > vi;
vi.resize(5);
for(int i=0;i<5;i++)
vi.resize(5,0);
-----code----

I can compile it and it works right on my gcc, but when I compile and
test it using a system on some other unknown machine, it can not work.
Output the vi matrix can only display the first row.

I want to know if vector can be used in this way? Is it supported by c+
+ std? Is there any fault to my code? thanks.
 
L

Lionel B

Hi, a question about vectors

----code---
vector<vector<int> > vi;
vi.resize(5);
for(int i=0;i<5;i++)
vi.resize(5,0);
-----code----

I can compile it and it works right on my gcc, but when I compile and
test it using a system on some other unknown machine, it can not work.
Output the vi matrix can only display the first row.

I want to know if vector can be used in this way? Is it supported by c+
+ std? Is there any fault to my code? thanks.


Looks ok to me. How are you displaying the result? Maybe the problem lies
there.

BTW, a more concise way of achieving the same thing is:

vector< vector<int> > vi(5,vector<int>(5,0));
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top