multiset::const_iterator : multiset iterator « Set Multiset « C++

Home
C++
1.Bitset
2.Class
3.Console
4.Data Structure
5.Data Type
6.Deque
7.Development
8.File
9.Function
10.Generic
11.Language
12.List
13.Map Multimap
14.Overload
15.Pointer
16.Qt
17.Queue Stack
18.Set Multiset
19.STL Algorithms Binary search
20.STL Algorithms Heap
21.STL Algorithms Helper
22.STL Algorithms Iterator
23.STL Algorithms Merge
24.STL Algorithms Min Max
25.STL Algorithms Modifying sequence operations
26.STL Algorithms Non modifying sequence operations
27.STL Algorithms Sorting
28.STL Basics
29.String
30.Valarray
31.Vector
C / ANSI-C
C Tutorial
C++ Tutorial
Visual C++ .NET
C++ » Set Multiset » multiset iteratorScreenshots 
multiset::const_iterator
  
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include <vector>

using namespace std;
class Dog
{
   public:
   Dogstring name = "Unknown", string breed = "A",int year = 2000 );
   bool operator<const Dog& rhs const;

   string breed() const;
   string name() const;

   void print() const;

   int year() const;

   private:
   string breed_;
   string name_;
   int year_;
};

inline
Dog::Dogstring name, string breed, int year )
   : breed_breed ), name_name ), year_year )
{} // empty

inline
bool Dog::operator<const Dog& rhs const
return name() < rhs.name()}

inline
string Dog::breed() const
return breed_; }

inline
string Dog::name() const
return name_; }

inline
void Dog::print() const
{
   cout << name() << ", a " << breed() << ", won in " << year()
      << endl;
}

inline
int Dog::year() const
return year_; }

bool equal_breedconst Dog winner, string breed );


int main( )
{
   const char* breed[] "A","B""C","D""E" };
   const char* name[] "a","b""c","d""e" };
   const int year[] 19711972197319741975 };
   const int num_dogs = sizeofbreed / sizeofbreed[0] );

   vector<Dog> v;
   forint i = 0; i < num_dogs; ++i )
      v.push_backDogname[i], breed[i], year[i] ) );

   const Dog query"A" );
   cout << query.name();

   set<Dog> winner_setv.begin(), v.end() );
   set<Dog>::const_iterator winner_set_end = winner_set.end();

   // search in the set by value
   set<Dog>::const_iterator spot = winner_set.findquery );
   ifspot != winner_set_end )
      spot->print();
   else
      cout << query.name() << " never won best-in-show\n";

   const string query_breed"A" );
   forspot = winner_set.begin(); spot != winner_set_end; ++spot )
      ifspot->breed() == query_breed )
         break;

}

inline
bool equal_breedconst Dog winner, string breed )
return winner.breed() == breed; }
  
    
  
Related examples in the same category
1.iterator that cannot be used to change element values in multiset
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.