keyert
keyert

Reputation: 285

If a standard C++ library function returns an int for a char value, does it need to be casted?

For example, the ifstream function ifstream infile; infile.peek() //returns an integer

Do I need to cast this int return value as a char or can I compare it directly to another char? If the latter is the case, does this mean char to char comparison just checks to see if integer ascii values are the same?

Thanks.

Upvotes: 0

Views: 107

Answers (1)

Sebastian Hoffmann
Sebastian Hoffmann

Reputation: 11482

Comparing it with a char literal e.g 'c' should work due to Integral Promotion

Upvotes: 2

Related Questions