boblink 2015-06-10 15:30 采纳率: 66.7%
浏览 1890

STL inserter插入器插入过程

#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)版本,则无此问题
求大神解疑

  • 写回答

3条回答

  • WorldMobile 2015-06-11 00:34
    关注

    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");
    }
    
    
    评论

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题