Thread: STL Container, key with two values?

  1. #1
    Registered User
    Join Date
    Apr 2004
    Location
    Ohio
    Posts
    147

    STL Container, key with two values?

    Which STL container should I use to store information about a 'record' (don't know a better name) that contains the key and two values? E.g., is there anything that looks like this:

    Code:
    std::whatever <type1, type2, type3> blah;
    
    blah.find(keyValue)->third;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    std::map<keytype, std::pair<value1type, value2type> > perhaps?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Location
    Ohio
    Posts
    147
    Awesome. I think that's exactly what I needed. Thank you!

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Or use a class so you can extend with more values later (if needed).
    Code:
    class Record
    {
      std::string Name;
      int Value;
    }
    
    std::map<Key, Record>
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Location
    Ohio
    Posts
    147
    Don't need to extend it later. I just basically need to store an int value and a time stamp. No need to create a whole class when I can use this method.

    Thanks for the tip, though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. stl container to store more than 1 type
    By sujeet1 in forum C++ Programming
    Replies: 7
    Last Post: 05-09-2007, 04:10 AM
  3. Assign Character Arrays data from an STL Container
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 12-05-2001, 10:33 AM
  4. BST/Red and Black Tree
    By ghettoman in forum C++ Programming
    Replies: 0
    Last Post: 10-24-2001, 10:45 PM