vector::empty

测试该向量是否包含任何元素。

bool empty( ) const;

返回值

如果向量为空,则为 true;如果矢量不为空,则为 false

示例

// vector_empty.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;   
   vector <int> v1;

   v1.push_back( 10 );

   if ( v1.empty( ) )
      cout << "The vector is empty." << endl;
   else
      cout << "The vector is not empty." << endl;
}
  

要求

标头:<vector>

命名空间: std

请参见

参考

vector 类

vector::empty、vector::erase 和 vector::push_back

标准模板库