++



         

multimap multiset - 2


void code_fragment()

{

multimap< string, string > authors;

// ...

string search_item( "Haruki Murakami" );

while ( cin && cin >> search_item )

switch ( authors.count( search_item ))

{

//

case 0:

break;

// 1, find()

case 1: {

multimap< string, string >: iterator iter;

iter = authors.find( search_item );

// ...

break;

}

// ...

default:

{

typedef multimap<string,string>::iterator iterator;

pair< iterator, iterator > pos;

// pos.first - 1-

// pos.second - 1-

//

pos = authors.equa1_range( search_item );

for (; pos.first != pos.second; pos.first++ )

// ...

}

}

}

multimap multiset map set. equal_range() , :

#include <multimap>

#include <string>

typedef multimap< string, string >::iterator iterator;

pair< iterator, iterator > pos;

string search_item( "Kazuo Ishiguro" );

// authors - multimap<string, string>

//

// authors.erase( search_item );

pos = authors.equa1_range( search_item );

authors.erase( pos.first, pos.second );

- insert() , . :

typedef multimap<string,string>::value_type valType;

multimap<string,string> authors;

// Barth

authors.insert( valType (

string( "Barth, John" ),

string( "Sot-Weed Factor" )));

// Barth

authors.insert( va1Type(

string( "Barth, John" ),

string( "Lost in the Funhouse" )));

multimap . :

authors[ "Barth, John" ]; // : multimap

6.28

6.14 multimap . ? ? ?