Thread: STL question: vector size (2 dimension)

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    4

    STL question: vector size (2 dimension)

    I have a

    vector < vector<int> > TwoDim;


    What does TwoDim.size() give me? Is it (x*y), assuming x = rows, y = columns in the sense of an array?

    How do I get the size of x?
    How do I get the size of y?


    Thanks,
    codeguy

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It gives the number of vector<int> in your vector (aka, the size of x).
    vector[n].size() gives the size of your y size.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    It gives the number of vector<int> in your vector (aka, the size of x).
    vector[n].size() gives the size of your y size.
    And it's worth noting that vector[0].size() may well be a completely different number than vector[1].size() for example.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Which is why Boost.MultiArray is a better choice for most applications than jagged vectors.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. STL preformance question
    By l2u in forum C++ Programming
    Replies: 9
    Last Post: 12-07-2006, 05:36 PM
  2. Quick Question about the Efficiency of the STL
    By Reisswolf in forum C++ Programming
    Replies: 8
    Last Post: 08-17-2006, 10:03 AM
  3. Fractals and Hausdorff dimension
    By Sang-drax in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-16-2005, 02:16 PM
  4. STL algorithm question
    By Reggie in forum C++ Programming
    Replies: 1
    Last Post: 04-22-2003, 09:04 AM
  5. question about STL
    By free2run in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2002, 12:12 PM