int main() { DataMap sightings; generate_n( inserter(sightings, sightings.begin()), 50, SightingGen(animals)); // Print everything: copy(sightings.begin(), sightings.end(), ostream_iterator<Sighting>(cout, "\n")); // Print sightings for selected animal: while (true) { cout << "select an animal or 'q' to quit: "; for (int i = 0; i < animals.size(); i++) cout << '[' << i << ']' << animals[i] << ' '; cout << endl; string reply; cin >> reply; if (reply.at(0) == 'q') return 0; istringstream r(reply); int i; r >> i; // Convert to int i %= animals.size(); // Iterators in "range" denote begin, one // past end of matching range: pair<DMIter, DMIter> range = sightings.equal_range(animals[i]); copy(range.first, range.second, ostream_iterator<Sighting>(cout, "\n")); } } ///:~
int main() { DataMap sightings; generate_n( inserter(sightings, sightings.begin()), 50, SightingGen(animals)); // Print everything: copy(sightings.begin(), sightings.end(), ostream_iterator<Sighting>(cout, "")); // Print sightings for selected animal: for(int count = 1; count < 10; count++) { // Use menu to get selection: // int i = menu(); // Generate randomly (for automated testing): int i = rand() % animals.size(); // Iterators in "range" denote begin, one // past end of matching range: pair<DMIter, DMIter> range = sightings.equal_range(animals[i]); copy(range.first, range.second, ostream_iterator<Sighting>(cout, "")); } } ///:~