vector of vector's

Discussion in 'C++' started by thomas, Jul 1, 2008.

  1. thomas

    thomas Guest

    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.
    thomas, Jul 1, 2008
    #1
    1. Advertising

  2. thomas

    Lionel B Guest

    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.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
    Lionel B, Jul 1, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. learningjava
    Replies:
    5
    Views:
    2,257
    Miguel De Anda
    Oct 17, 2003
  2. pmatos
    Replies:
    6
    Views:
    23,721
  3. Replies:
    8
    Views:
    1,887
    Csaba
    Feb 18, 2006
  4. Javier
    Replies:
    2
    Views:
    541
    James Kanze
    Sep 4, 2007
  5. Rushikesh Joshi
    Replies:
    0
    Views:
    343
    Rushikesh Joshi
    Jul 10, 2004
Loading...

Share This Page