Thread: vectors, declaring and initialising

  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,817
    Code:
    vector< vector<Tile> > tiles;
    
    ...
    
    tiles.resize(50);
    for( vector<vector<Tile> >::iterator it = tiles.begin(); it != tiles.end(); ++it )
        it->resize(50);
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  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