vectors, declaring and initialising

This is a discussion on vectors, declaring and initialising within the C++ Programming forums, part of the General Programming Boards category; Hi i would like to know how to declare a multi dimensional vector and then later initialize its size. normally ...

  1. #1
    h4x0r1ng t3h m41nfr4m3!!1 r0bbb's Avatar
    Join Date
    Mar 2005
    Location
    West London
    Posts
    9

    vectors, declaring and initialising

    Hi i would like to know how to declare a multi dimensional vector and then later initialize its size.

    normally id declare and init a vector like :

    vector< vector<Tile> > tiles(50, vector<Tile>(50));

    creating a multidimensional vector with 50 rows and 50 cols.

    i know how to declare a vector and not init its size :

    vector< vector<Tile> > tiles;

    but how can i later declare the number of rows and columns.

    cheers

    rob.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    Code:
    vector< vector<Tile> > tiles;
    
    ...
    
    tiles.resize(50);
    for( vector<vector<Tile> >::iterator it = tiles.begin(); it != tiles.end(); ++it )
        it->resize(50);
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    h4x0r1ng t3h m41nfr4m3!!1 r0bbb's Avatar
    Join Date
    Mar 2005
    Location
    West London
    Posts
    9
    amazing, thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Declaring and initialising constant nested arrays
    By officedog in forum C Programming
    Replies: 6
    Last Post: 10-28-2008, 09:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21