2d vectors question

This is a discussion on 2d vectors question within the C++ Programming forums, part of the General Programming Boards category; When declaring a 2d vector, is the space between the last two >'s required? Code: vector<vector<int> > v; Or is ...

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

    2d vectors question

    When declaring a 2d vector, is the space between the last two >'s required?
    Code:
    vector<vector<int> > v;
    Or is this fine?
    Code:
    vector<vector<int>> v;
    I heard that the extra space is required, but I'm not sure.

  2. #2
    verbose cat
    Join Date
    Jun 2003
    Posts
    209
    If you don't put a space between the two >'s the compiler may interpret it as the >> character ( think cin >> x; ) and it won't compile.

    When I use this kind of construct, I usually do
    Code:
    vector< vector<int> >;
    The extra space on both sides helps me see it more clearly. However,

    Code:
    vector<vector<int> >;
    is just as correct (but asymmetrical and ugly in my opinion).
    abachler: "A great programmer never stops optimizing a piece of code until it consists of nothing but preprocessor directives and comments "

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    Compilers will start allowing you to skip the space soon, the change will be in the next standard. Until then, it is required.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2d array question
    By goofy26 in forum C Programming
    Replies: 10
    Last Post: 03-02-2009, 10:34 AM
  2. Quick Question: 2D Array with char **
    By Phoenix_Rebirth in forum C Programming
    Replies: 4
    Last Post: 01-29-2009, 07:33 AM
  3. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 11:35 AM
  4. vector of vectors question
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 02-10-2003, 03:02 PM
  5. Dynamic 2D arrays question
    By MadStrum! in forum C Programming
    Replies: 7
    Last Post: 02-08-2003, 05:54 AM

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