I have two questions related to the vector class of the standard library in C++.
How can I check whether a value (let's say of an integer) already exists in a vector?
What I want in words is as follows: "if the integer already exists in the vector, next one, else add it at the end of the vector."
How do I apply a function that holds arguments to every element in the vector? (It seems I can't do that with for_each)
In words: "for each z element in the vector apply MyAddFn(i,j)"
... or maybe I'm not on the right track with the stl vector sequence container, and I should define my own iterator?
1)
std::find(v.begin(), v.end(), 5) == v.end() // checks that vector<int> v has no value 5.
2) Use new C++11 std::bind for example, but for real advice i need more context of use MyAddFn.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With