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

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常