STL Container, key with two values?

This is a discussion on STL Container, key with two values? within the C++ Programming forums, part of the General Programming Boards category; Which STL container should I use to store information about a 'record' (don't know a better name) that contains the ...

  1. #1
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    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;
    - Leeor

  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
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    Awesome. I think that's exactly what I needed. Thank you!
    - Leeor

  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
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    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.
    - Leeor

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, 09:32 AM
  2. stl container to store more than 1 type
    By sujeet1 in forum C++ Programming
    Replies: 7
    Last Post: 05-09-2007, 05: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, 11:45 PM

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