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

Recommended Answers

All 2 Replies

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>

?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.