简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM