STL set常用操作

// 使用占用空间可能会很大

  iterator begin ( ); 
iterator end ( );
void clear ( );
size_type count ( cont key_type& x ) const;
bool empty ( ) const;
void erase ( iterator position );
size_type erase ( const key_type& x );
void erase ( iterator first, iterator last );
iterator find ( const key_type& x ) const;
size_type size( ) const;

pair<iterator,bool> insert ( const value_type& x );
iterator insert ( iterator position, const value_type& x );

一个示例:

#include <iostream>
#include <set>
using namespace std;

int main ()
{
set<int> myset;
set<int>::iterator it;

myset.insert (100);
myset.insert (200);
myset.insert (300);

cout << "myset contains:";
for (it=myset.begin(); it!=myset.end(); ++it)
cout << " " << *it;

myset.clear();
myset.insert (1101);
myset.insert (2202);

cout << "\nmyset contains:";
for (it=myset.begin(); it!=myset.end(); ++it)
cout << " " << *it;

cout << endl;

return 0;
}

 

来源于C++ LibraryFunctions.chm(由伯爵www.CPLUSPLUS.com 批量下载整理,所有权归原文作者所有,仅供学习交流使用.)



你可能感兴趣的:(set)