📄 fig20_19.cpp
字号:
// Fig. 20.19: fig20_19.cpp
// Testing Standard Library class multiset
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
const int SIZE = 10;
int a[ SIZE ] = { 7, 22, 9, 1, 18, 30, 100, 22, 85, 13 };
typedef multiset< int, less< int > > ims;
ims intMultiset; // ims for "integer multiset"
ostream_iterator< int > output( cout, " " );
cout << "There are currently " << intMultiset.count( 15 )
<< " values of 15 in the multiset\n";
intMultiset.insert( 15 );
intMultiset.insert( 15 );
cout << "After inserts, there are "
<< intMultiset.count( 15 )
<< " values of 15 in the multiset\n";
ims::const_iterator result;
result = intMultiset.find( 15 ); // find returns iterator
if ( result != intMultiset.end() ) // if iterator not at end
cout << "Found value 15\n"; // found search value 15
result = intMultiset.find( 20 );
if ( result == intMultiset.end() ) // will be true hence
cout << "Did not find value 20\n"; // did not find 20
intMultiset.insert( a, a + SIZE ); // add array a to multiset
cout << "After insert intMultiset contains:\n";
copy( intMultiset.begin(), intMultiset.end(), output );
cout << "\nLower bound of 22: "
<< *( intMultiset.lower_bound( 22 ) );
cout << "\nUpper bound of 22: "
<< *( intMultiset.upper_bound( 22 ) );
pair< ims::const_iterator, ims::const_iterator > p;
p = intMultiset.equal_range( 22 );
cout << "\nUsing equal_range of 22"
<< "\n Lower bound: " << *( p.first )
<< "\n Upper bound: " << *( p.second );
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -