Home > C++, VC++ > How to force show/hide + sign for numbers?

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…

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

Advertisements
  1. Sarath
    February 13, 2009 at 9:40 am

    That’s a nice input…

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: