Array in a Map

This is a discussion on Array in a Map within the C++ Programming forums, part of the General Programming Boards category; I was just curious if there was a way to pass an array as a value into a map without ...

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    15

    Array in a Map

    I was just curious if there was a way to pass an array as a value into a map without using a pointer. I am trying to do something like:

    Code:
    map <string,array> nameMap;
    Here the key would be a string and the value would be an array. I was curious if I could do this without using pointers. When I compile this I get an error

    Error:
    Code:
    17  `array' was not declared in this scope 
    17  template argument 2 is invalid 
    17  template argument 4 is invalid 
    17  ISO C++ forbids declaration of `nameMap' with no type
    Line 17 here being the line I posted above.

    This is just for my curiosity, let me know if anyone has any solutions.

  2. #2
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    No, as a map is a replacement for an array. However, you can create the map and then use a for loop to iterate through and put the array's elements in the map.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    You could use a std::vector:
    Code:
    std::map<std::string, std::vector<T> >
    Where T is the type you want to store in the vector.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  2. [question]Analyzing data in a two-dimensional array
    By burbose in forum C Programming
    Replies: 2
    Last Post: 06-13-2005, 08:31 AM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-12-2004, 12:15 AM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 05:27 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM

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