#include
#include
#include
using namespace std;
int main()
{
listlst;
for(int i=1;i lst.push_back(i);
listlst2;
copy(lst.begin(),lst.end(),inserter(lst2,lst2.begin()));
cout<<"lst2:begin(): ";
for(auto it=lst2.begin();it!=lst2.end();it++)
cout<<*it<<ends;
cout<<endl;
system("pause");
}
为何输出为1 2 3 4而不是4 3 2 1,不是说inserter插入器要把元素插在第二个参数指定的元素之前么?
本人理解一是第一次插入结果1,第二次应该为2,1...故有上述问题
二是inserter插入器调用了insert(p,b,e)版本,则无此问题
求大神解疑
push_bach函数:
函数原型:
iterator push_bash();
功能:在容器的尾端插入一个数据
楼主的这段代码好像问题比较多,编译肯定会出错
#include
#include
#include
using namespace std;
int main()
{
list lst;
for(int i=1;i lst.push_back(i);
list lst2;
copy(lst.begin(), lst.end(), inserter(lst2,lst2.begin()));
cout << "lst2:begin(): ";
for(auto it=lst2.begin();it!=lst2.end();it++)
cout << *it << ends;
cout << endl;
system("pause");
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。