STL Container6: Set

来源:互联网 发布:相贯线切割机编程 编辑:程序博客网 时间:2024/06/07 00:13

 

// Set_Process.cpp : Defines the entry point for the console application.

//

 

 

#include <iostream>

 

using std::cout;

using std::endl;

 

#include <set>

#include <iterator>

 

typedef std::set< double, std::less< double > > double_set;

 

int _tmain(int argc, _TCHAR* argv[])

{

    const int SIZE = 5;

    double a[ SIZE ] = { 2.1, 4.2, 9.5, 2.1, 3.7 };

 

    double_set doubleSet( a, a + SIZE );

    std::ostream_iterator< double > outputIt( cout, " " );

 

    cout<<"double Set contains: ";

    std::copy( doubleSet.begin(), doubleSet.end(), outputIt );

 

    std::pair< double_set::const_iterator, bool > p;

 

    p = doubleSet.insert( 13.8 );

 

    cout<< "/n/n" << *(p.first)

        << ( p.second ? " was": " was not") << " inserted";

 

    cout<<"/ndoubleSet contains: ";

    std::copy( doubleSet.begin(), doubleSet.end(), outputIt );

 

    p = doubleSet.insert( 9.5 );

 

    cout<<"/n/n" << *( p.first )

        << ( p.second ? " was" : " was not" ) << " inserted";

 

    cout<< "/ndoubleSet contains: ";

    std::copy( doubleSet.begin(), doubleSet.end(), outputIt );

 

    cout<<endl;

 

    return 0;

}

 

 

原创粉丝点击