64,675
社区成员
发帖
与我相关
我的任务
分享
void main()
{
std::list <int> cclst;
std::list <int> value(1000, 0);
// 方法一
for (int i = 0; i < 5; ++i)
cclst.insert(cclst.begin(), 1000, 1);
// 方法二
for (int j = 0; j < 5; ++j)
cclst.insert(cclst.begin(), value.begin(), value.end());
// 方法三
for (int k = 0; k < 5; ++k)
copy(value.begin(), value.end(), back_inserter<std::list <int> >(cclst));
copy(cclst.begin(), cclst.end(), ostream_iterator<int>(cout, " "));
}
#include <iostream>
#include <list>
using namespace std;
void test(list<int> IntList)
{
int i;
const int count=1000;
static list<int>::iterator Iter=IntList.begin();
cout<<*Iter<<endl;
for(i=0,Iter; Iter!=IntList.end()&&( i<count ); Iter++, i++)
cout<<*Iter<<" ";
cout<<"i :" <<i<<endl;
cout<<"The last one is: "<<*Iter<<endl;
}
int main()
{
list<int> cclist;
list<int>::iterator Iter=cclist.begin();
for(int i=0; i<2000; i++)
cclist.push_back(i);
cout<<cclist.size()<<endl;
test(cclist);
test(cclist);
return 0;
}
函数里面的static Iter有点问题,当第二次进入函数的时候并不是从第1001个元素开始;
lx的兄弟们帮忙改进一下吧,^_^