Reputation: 1
I am trying to use a find_if Boolean function to return true if:
My code:
/* predicate for find_if */
bool exam_pred(const exam_struct &a)
{
if ((a.Z=<10)&&(a.name="john"))
{
return true;
}
}
exam_struct{
int x,y;
double Z;
string name;
};
It doesn't compile when I set a.name="john"
. So my question is how do implement the a.name="john";
into my boolean?
Upvotes: 0
Views: 249
Reputation: 21635
you should indeed use the ==
operator.
I was wrong suggesting strcmp before, since you are using strings.
code:
struct exam_struct {
int x, y;
double Z;
string name;
};
/* predicate for find_if */
bool exam_pred(const exam_struct& a)
{
return a.Z <= 10 && a.name=="john";
}
note that in your original code you do not return false
when the check false.
Upvotes: 3
Reputation: 41968
=
is the assignment operator. Use ==
for equality comparisons. And the smaller-or-equals operator is <=
, not =<
.
Upvotes: 2