简体   繁体   English

C ++ STL列表大小

[英]C++ STL list size

i've got some problem/ i don't understand something and it cause this problem :) 我有一些问题/我不明白的东西,它导致这个问题:)

Here is some code: 这是一些代码:

list<Walec>lista;

remove_copy_if(vec.begin(),vec.end(), lista.begin(),Warunek_na_Wysokosc(sredniasu));
 copy(lista.begin(),lista.end(),ostream_iterator<Walec>(cout, " \n"));

And here is Warunek_Na_Wysokosc definition: 这里是Warunek_Na_Wysokosc定义:

struct Warunek_na_Wysokosc
{
    double wys;

   Warunek_na_Wysokosc(const double& h_): wys(h_){ }

    bool operator()(const Walec& w)
    {
        return w.h >= wys;
    }

};

The thing is i get some memory problems if i let it be like that, i mean instructions in main function, and there are none if i set list size. 事情是我得到一些内存问题如果我让它像那样,我的意思是主要功能中的指令,如果我设置列表大小没有。 But i want it to be set automatically, should i use some insert function? 但我希望它能自动设置,我应该使用一些插入功能吗? How to correct this? 怎么纠正这个? :) Thanks! :) 谢谢!

I think you want to use inserter here: 我想你想在这里使用插件

remove_copy_if(vec.begin(),vec.end(),
               std::inserter(lista,lista.end()),
               Warunek_na_Wysokosc(sredniasu));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM