Thread: Initializing 2D 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
    28,413
    It should be something like this:
    Code:
    std::vector<std::vector<int> > matrix2d(255, std::vector<int>(255));
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 08:36 PM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 10:38 AM
  3. Vector class
    By Desolation in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 05:44 PM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 12: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