设为首页 加入收藏

TOP

标准模板库(STL)List介绍(十四)
2011-06-07 12:31:23 来源: 作者: 【 】 浏览:9190
Tags:标准 模板 STL List 介绍
 
  
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  
  
首页 上一页 11 12 13 14 15 16 17 下一页 尾页 14/18/18
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇 C++语言的url encode 和decode 下一篇C++ map的基本操作和使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: