1、assign——初始化或者重置容器内元素
#include <iostream> #include <list> #include <algorithm> #include <iterator> using namespace std; int main () { int ary[]={1,2,3,4,5}; list<int> l; // 将数组ary分配给l容器 l.assign(ary,ary+5); copy(l.begin(),l.end(), ostream_iterator<int>(cout," ")); cout << endl; // 用3个100替换l容器内容 l.assign(3,100); copy(l.begin(),l.end(), ostream_iterator<int>(cout," ")); cout << endl; return 0; } 运行结果: // 1 2 3 4 5 // 100 100 100