Thread: vector <string> in a map

  1. #1
    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
    28,413
    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.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    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, 09:42 AM
  2. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  3. Creating a map engine.
    By suzakugaiden in forum Game Programming
    Replies: 11
    Last Post: 06-21-2005, 05: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