fig20_20.cpp

来自「经典vc教程的例子程序」· C++ 代码 · 共 37 行

CPP
37
字号
// Fig. 20.20: fig20_20.cpp
// Testing Standard Library class set
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
   typedef set< double, less< double > > double_set;
   const int SIZE = 5;
   double a[ SIZE ] = { 2.1, 4.2, 9.5, 2.1, 3.7 };   
   double_set doubleSet( a, a + SIZE );;
   ostream_iterator< double > output( cout, " " );

   cout << "doubleSet contains: ";
   copy( doubleSet.begin(), doubleSet.end(), output );

   pair< double_set::const_iterator, bool > p;

   p = doubleSet.insert( 13.8 ); // value not in set
   cout << '\n' << *( p.first ) 
        << ( p.second ? " was" : " was not" ) << " inserted";
   cout << "\ndoubleSet contains: ";
   copy( doubleSet.begin(), doubleSet.end(), output );

   p = doubleSet.insert( 9.5 );  // value already in set
   cout << '\n' << *( p.first ) 
        << ( p.second ? " was" : " was not" ) << " inserted";
   cout << "\ndoubleSet contains: ";
   copy( doubleSet.begin(), doubleSet.end(), output );

   cout << endl;
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?