Cpp - Output Positive Negative Numbers

Introduction

When negative numbers are output as decimals, the output will always include a sign.

You can use the showpos manipulator to output signed positive numbers.

cout << dec << showpos << 11; //Output: +11 

You can use noshowpos to revert to the original display mode.

When octal or hexadecimal numbers are output, the bits of the number to be output are always interpreted as unsigned!

The output shows the bit pattern of a number in octal or hexadecimal format.

cout << dec << -1 << "   " << hex << -1; 

This statement causes the following output on a 32-bit system:

-1   ffffffff  

Related Topic