The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-06-2008
matrixmadhan matrixmadhan is offline
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,454
here is a sample code

Code:
#include <iostream>
#include <map>
#include <string>
using namespace std;

int main()
{
  multimap<string, string> names;
  string n;

  names.insert(pair<string, string>("key1", "F"));
  names.insert(pair<string, string>("key2", "T"));
  names.insert(pair<string, string>("key3", "R"));

  multimap<string, string>::iterator p;

  cout << "Enter last name: ";
  cin >> n;

  p = names.find(n);
  if(p != names.end()) { // found a name
    do {
      cout << n << ", " << p->second;
      cout << endl;
      p++;
    } while (p != names.upper_bound(n));
  }
  else{
    cout << "Name not found.\n";
  }
  return 0;
}
Reply With Quote