Initializing 2D Vector?

This is a discussion on Initializing 2D Vector? within the C++ Programming forums, part of the General Programming Boards category; Hi forum! I wonder how can I a initialize a 255x255 Square Matrix ? I thought that Using a Vector ...

  1. #1
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126

    Question Initializing 2D Vector?

    Hi forum!

    I wonder how can I a initialize a 255x255 Square Matrix ?

    I thought that Using a Vector should be the easy approach, but how can I initialize them?


    I have:
    Code:
    Vector < Vector <int> > matrix2d; //this should be initialized as 255x255 2D vector
    and offcourse when I do something like matrix[j][i] = 123;
    I get a EXEC_BAD_ADDRESS!.

    Any help is very appreciated!

    thanks.
    Mac OS 10.6 Snow Leopard : Darwin

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,166
    It should be something like this:
    Code:
    std::vector<std::vector<int> > matrix2d(255, std::vector<int>(255));
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2006
    Location
    japan
    Posts
    126
    Thanks!,
    That was fast
    Mac OS 10.6 Snow Leopard : Darwin

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 11:38 AM
  3. Vector class
    By Desolation in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 06:44 PM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 01:34 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM

Tags for this Thread


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