← Back to Streams
Question 639
Hex and Decimal
Hex and Decimal
Write a functionvoid printHexDec(ostream& out, int n)that writesnin decimal, then a space, an equals sign, a space and0x, thennagain in lowercase hexadecimal (no padding), then a newline — for 255 the line is255 = 0xff, for 0 it is0 = 0x0. Print the0xprefix as a plain string, switch the stream tohexfor the second number, and switch it back withdecbefore returning. The test prints another integer (100) through the same stream right after the call (see Expected Output). Do NOT write a main function.
Expected Output:
255 = 0xff 100 4096 = 0x1000 0 = 0x0 42
= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Streamsostream
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.