How to force show/hide + sign for numbers?

We know that ‘-‘ i.e. minus is always displayed for numbers but how about ‘+’ sign. Is there a way to show this sign using output streams in c++? The answer is yes! Use “showpos” function and use “noshowpos” to disable this functionality…

[sourcecode language=’cpp’]int main()
{
   cout << showpos   << 10 << " " << -100 << endl;    cout << noshowpos << 10 << " " << -100  << endl;    return 0; } // Output +10 -100 10 -100 [/sourcecode]

2 thoughts on “How to force show/hide + sign for numbers?

Appreciate your comments...