CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2005
    Posts
    1,030

    A question regarding multimap

    There is one key having multiple values in a multimap. If I want to erase just one value corresponding to this key, how can I do that? If I can't do that, what is more appropriate data structure to use if I want to dynamically change the values associated with a key?

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: A question regarding multimap

    You can use the version of the erase member function that takes an iterator to the element that you wish to erase.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Jul 2005
    Posts
    1,030

    Re: A question regarding multimap

    Quote Originally Posted by laserlight View Post
    You can use the version of the erase member function that takes an iterator to the element that you wish to erase.
    It works. Thanks.

  4. #4
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: A question regarding multimap

    Depending on your design, if what you want are "several values associated to 1 key", rather than "several key-value pairs with the same key", then a "map<key, container<values>>" could be a better alternative.

    But it's apples and oranges.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured