Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > vector of vector's

Reply
Thread Tools

vector of vector's

 
 
thomas
Guest
Posts: n/a
 
      07-01-2008
Hi, a question about vectors

----code---
vector<vector<int> > vi;
vi.resize(5);
for(int i=0;i<5;i++)
vi[i].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.
 
Reply With Quote
 
 
 
 
Lionel B
Guest
Posts: n/a
 
      07-01-2008
On Tue, 01 Jul 2008 06:29:01 -0700, thomas wrote:

> Hi, a question about vectors
>
> ----code---
> vector<vector<int> > vi;
> vi.resize(5);
> for(int i=0;i<5;i++)
> vi[i].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));

--
Lionel B
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Initializing vector<vector<int> > and other vector questions... pmatos C++ 6 04-26-2007 05:39 PM
Free memory allocate by a STL vector, vector of vector, map of vector Allerdyce.John@gmail.com C++ 8 02-18-2006 12:48 AM
how the vector is created, how to pass vector to webservices method apachesoap:Vector Rushikesh Joshi Perl Misc 0 07-10-2004 01:04 PM
how do i create a vector within a vector ? learningjava Java 5 10-17-2003 10:19 PM



Advertisments