c++ - Boolean function -
i trying use find_if boolean function return true if:
- z =<10;
- name="john" (all lower case)
my code:
/* predicate 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 set a.name="john"
. question how implement a.name="john";
boolean?
you should indeed use ==
operator.
i wrong suggesting strcmp before, since using strings.
code:
struct exam_struct { int x, y; double z; string name; }; /* predicate find_if */ bool exam_pred(const exam_struct& a) { return a.z <= 10 && a.name=="john"; }
note in original code not return false
when check false.
Comments
Post a Comment