标准模板库(STL)List介绍(十四)

2011-06-07 12:31:23 · 作者: · 浏览: 9225
 
  
List 构造函数  
我们已经象这样定义了list:  
  
list<int> Fred;  
  
你也可以象这样定义一个list,并同时初始化它的元素:  
  
// define a list of 10 elements and initialise them all to 0  
list<int> Fred(10, 0);  
// list now contains 0,0,0,0,0,0,0,0,0,0  
  
或者你可以定义一个list并用另一个STL容器的一个范围来初始化它,这个STL容器不一定是一个list, 仅仅需要是元素类型相同的的容器就可以。  
  
vector<int> Harry;  
Harry.push_back(1);  
Harry.push_back(2);  
#  
// define a list and initialise it with the elements in Harry  
list<int> Bill(Harry.begin(), Harry.end());  
// Bill now contains 1,2