Getting an error when using the function find_if on STL

I am getting an error when using this function:

position = find_if(charList.begin(), charList.end(), isupper);
The function: find(....) works fine but find_if gives an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<cctype>

using namespace std;

int main() {
	
	char cList[10] = {'a', 'i','C', 'd', 'e', 'f', 'o', 'H', 'u', 'j'};
		ostream_iterator<char> screen(cout, " ");
	vector<char> charList(cList, cList + 10);
	vector<char>::iterator position;
	
	position = find(charList.begin(), charList.end(), 'd');
	//	copy(charList.begin(), charList.end(), screen);              
	cout<<endl;
		cout<< endl << *position;
      position = find_if(charList.begin(), charList.end(), isupper);
	cout << endl << *position;

}
One of the most important things to tell us when you have an error is what that error is.

As it is, this one is relatively simple, but you really should tell people what the error is. Knowing what the error is makes helping you much easier for us.

position = find_if(charList.begin(), charList.end(), ::isupper);
Hello Bopaki,

I will offer this as a thought. I put your program in VS 2015 and compiled with the C++11 standard and could not duplicate your error. The program ran fine.
producing a "d" and "C" for the output.

I did notice that main has no return statement. It works without, but looks better with the last line being "return 0;".

Both Moschops and JLBorges have good suggestions and if they do not work maybe check what standard the compiler is set up to use.

Hope that helps,

Andy
Topic archived. No new replies allowed.