共用方式為


set::empty

測試,如果集合是空的。

bool empty( ) const;

傳回值

true ,如果這個集合是空的; false ,如果這個集合不是空的。

範例

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

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

   if ( s1.empty( ) )
      cout << "The set s1 is empty." << endl;
   else
      cout << "The set s1 is not empty." << endl;

   if ( s2.empty( ) )
      cout << "The set s2 is empty." << endl;
   else
      cout << "The set s2 is not empty." << endl;
}
  

需求

標頭: <set>

命名空間: std

請參閱

參考

set 類別

set::empty 和 set::clear

標準樣板程式庫