Thread: Vector within a vector

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    220

    Vector within a vector

    Is it possible to have vectors made up of vectors?

    If so, how would I accomplish this? If not, is there an alternative that would provide the same result?

    I'm confused of how to do a vector within a vector....because I originally thought of:

    Code:
    vector<vector<string>> vstrInventory;
    For example, but that didn't seem right to me for some reason :/
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You have to use some spaces.
    Code:
    vector< vector<string> > vstrInventory;
    I'm not sure why.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The token >> makes the compiler confused when you use it with nested templates, so you must use a space between the any two > signs:

    std::vector<std::vector<std::string> > vec2D;

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    220
    Ahh ok, thanks guys
    OS: Windows XP Pro CE
    IDE: VS .NET 2002
    Preferred Language: C++.

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