vector <string> in a map

This is a discussion on vector <string> in a map within the C++ Programming forums, part of the General Programming Boards category; Code: map <string, vector <string> > macros; macros["some"][0] = "some string"; macros["another"][0] = "some string 2"; macros["another"][1] = "some string ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    vector <string> in a map

    Code:
    map <string, vector <string> > macros;
    
    macros["some"][0] = "some string";
    macros["another"][0] = "some string 2";
    macros["another"][1] = "some string 3";
    Whats wrong with that?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,112
    It should probably be:
    Code:
    map <string, vector <string> > macros;
    
    macros["some"].push_back("some string");
    macros["another"].push_back("some string 2");
    macros["another"].push_back("some string 3");
    Consider the problem with this:
    Code:
    vector<int> vec;
    vec[0] = 1;
    Clearly vec is empty, so vec[0] does not exist.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    Thank you..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding a Map to a program
    By Shogun32 in forum C++ Programming
    Replies: 1
    Last Post: 05-04-2009, 10:42 AM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 09:32 AM
  3. Creating a map engine.
    By suzakugaiden in forum Game Programming
    Replies: 11
    Last Post: 06-21-2005, 06:06 AM
  4. Searching STL Map Inside STL Map Object :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 11-14-2002, 09:11 AM
  5. my map is showing up 90 degrees turned!
    By frenchfry164 in forum C++ Programming
    Replies: 8
    Last Post: 03-28-2002, 02:32 PM

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