0

Hi,

I want to replace the numbers which are less than 5 in a container. So i write a code as follows. But it is not working. Please get me the solution for this. Destination container should be V2 itself. Where we have to specify destination container.

replace_if(V2.begin(),V2.end(),               //range
                   bind2nd(less<int>() ,5));          //replace criterion
2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by ambarisha.kn
0

Hi,

I want to replace the numbers which are less than 5 in a container.
[...]

replace_if(V2.begin(),V2.end(),  bind2nd(less<int>() ,5));          //replace criterion

Replace them with what? You're missing the last parameter for the replace_if() function. If you want to replace them with '1' for example, you should use replace_if(V2.begin(),V2.end(), bind2nd(less<int>() ,5),1); and did you remember to

#include <algorithm>
#include <functional>

?

0

Replace them with what? You're missing the last parameter for the replace_if() function. If you want to replace them with '1' for example, you should use replace_if(V2.begin(),V2.end(), bind2nd(less<int>() ,5),1); and did you remember to

#include <algorithm>
#include <functional>

?

Thanks , I got it. I was missed last parameter.

replace_if(V2.begin(),V2.end(),               //range
                   bind2nd(less<int>() ,5),0);          //replace criterion

Now its working.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.