Search code examples
c++coutcarriage-return

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.


Solution

  • 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;