L_Stud
L_Stud

Reputation: 43

How to print a '\n' character in Hex in c++

I am trying to print the hexidecimal value of '\n' using cout.

cout<< hex << '\n' << dec<< endl;

whenever that line of code is reached it just moves to a new line it does not print the hex value. Thank you guys very much.

Upvotes: 1

Views: 657

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595762

Streaming an actual '\n' character as-is will always output a line break. You need to type-cast the value to an integer instead:

cout <<  hex << (int)'\n' << dec << endl;

Upvotes: 5

Related Questions