How to find element in vector with find_if() with bind2nd() and ptr_fun() in C++

1 Answer

0 votes
#include <iostream> 
#include <algorithm>
#include <vector>
#include <functional>

using std::vector;
using std::cout;  
using std::endl;

int main()
{
	vector<char *> vec{ "c++", "c", "java", "php", "python" };

	vector<char *>::iterator it;

	it = find_if(vec.begin(), vec.end(), not1(std::bind2nd(std::ptr_fun(strcmp), "java")));

	if (it != vec.end()) 
		cout << "Found: " << *it << endl;

	cout << endl;
}



/*
run:

Found: java

*/

 



answered Apr 26, 2018 by avibootz
edited Dec 7, 2023 by avibootz
...