[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppMultimap

(C++) std::multimap

STL container class like a std::map, except that it can hold multiple values for one key.

Example

To add a key-value-pair, use std::multimap<T>::insert. To find a rang of values, use std::multimap<T>::equal_range. This method returns an std::pair of  ?iterators.

  1. include <map>
  2. include <string>
  3. include <iostream>
int main() { std::multimap<std::string,std::string> questions; questions.insert(std::make_pair("A prime number between 10 to 20","11")); questions.insert(std::make_pair("A prime number between 10 to 20","13")); questions.insert(std::make_pair("A prime number between 10 to 20","17")); questions.insert(std::make_pair("A prime number between 10 to 20","19")); typedef std::multimap<std::string,std::string>::const_iterator Iterator; const std::pair<Iterator,Iterator> answers = questions.equal_range("A prime number between 10 to 20"); for (Iterator i = answers.first; i!= answers.second; ++i) { std::cout << i->second << std::endl; } }


Code links

Links



last edited (February 7, 2007) by bilderbikkel, Number of views: 4976, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.