共用方式為


list::clear

清除清單中的所有項目。

void clear( );

範例

// list_clear.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main() {
   using namespace std;
   list <int> c1;
   
   c1.push_back( 10 );
   c1.push_back( 20 );
   c1.push_back( 30 );

   cout << "The size of the list is initially " << c1.size( ) << endl;
   c1.clear( );
   cout << "The size of list after clearing is " << c1.size( ) << endl;
}
  

需求

標題: <list>

命名空間: std

請參閱

參考

list Class

標準樣板程式庫