set::clear

清除集合的所有元素。

void clear( );

示例

// set_clear.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;   
   set <int> s1;
   
   s1.insert( 1 );
   s1.insert( 2 );

   cout << "The size of the set is initially " << s1.size( )
        << "." << endl;

   s1.clear( );
   cout << "The size of the set after clearing is " 
        << s1.size( ) << "." << endl;
}
  
  

要求

标头: <set>

命名空间: std

请参见

参考

set Class

set::empty 和 set::clear

标准模板库