Thread: Array in a Map

  1. #1
    Registered User
    Join Date
    Oct 2006

    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:

    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

    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
    Boston, Massachusetts
    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
    Seattle, WA
    You could use a std::vector:
    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."

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, 07:31 AM
  3. Template Array Class
    By hpy_gilmore8 in forum C++ Programming
    Replies: 15
    Last Post: 04-11-2004, 11:15 PM
  4. two dimensional dynamic array?
    By ichijoji in forum C++ Programming
    Replies: 6
    Last Post: 04-14-2003, 04:27 PM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM