multiset find使用...

#include #include #include #include #include using namespace std; typedef struct _NODE { string name; int id; _NODE(string name, int id) : name(name), id(id){}; friend ostream& operator<< (ostream &os, const _NODE &nod) { return os << "(" << nod.id <<", " << nod.name << ")" << endl; } friend bool operator<(const _NODE &nod, const _NODE &node) { return nod.id < node.id; } }NODE; template void _printf(const T &begin, const T &end) { ostream_iterator os(cout, ""); copy(begin, end, os); cout << endl; } int main(int argc, char *argv[]) { multiset mulSet; for(int i=0; i<10; i++) { NODE temp("string", rand() % 10); mulSet.insert(temp); } cout << "all elements in set are: " << endl; _printf(mulSet.begin(), mulSet.end()); int id; cout << "enter a word id to search: "; cin >> id; /*first find method*/ cout << "first method: " << endl; NODE temp("string", id); multiset::iterator it = mulSet.find(temp); if(it == mulSet.end()) cout << "no find the word" << endl; else { cout << "find the words: " << endl; multiset::size_type count = mulSet.count(temp); for(int i=0; i::iterator beg = mulSet.lower_bound(temp); multiset::iterator end = mulSet.upper_bound(temp); if(beg == end) cout << "no find the word" << endl; else { for(beg; beg != end; beg++) cout << *beg << endl; } system("PAUSE"); return EXIT_SUCCESS; }  

 

使用了两种方式实现在multiset中查找的功能...

你可能感兴趣的:(STL练习)