Using int to control an if statement

I can't see what is wrong here. The first line works fine. The second results in a compilation error "invalid initializer". I'm testing to see whether the first character in a string variable (init_value) is a '-' (ASCII value 45).

1
2
cout << int(init_value[0]) << endl;
if (int(init_value[0]) = 45)


Anybody see why this won't compile? Thanks.
if (a = b) - Wrong
if (a == b) - Correct

= is the assignment operator
== checks if they are equal
Last edited on
Thanks. Can't believe that I overlooked that.
Topic archived. No new replies allowed.