Home > C++, VC++ > How to display notational base for a number?

How to display notational base for a number?

Well what the heck do you mean by notational base? It just means the prefix we give for hexadecimal and octal numbers. So in C++ there is an io manipulator called ‘showbase’ which shows the base and ‘noshowbase’ which hides the base from display.

An e.g. from MSDN…

#include

int main( )
{
   using namespace std;
   int j = 100;

   cout << showbase << j << endl;   // dec is default    cout << hex << j << showbase << endl;    cout << oct << j << showbase << endl;    cout << dec << j << noshowbase << endl;    cout << hex << j << noshowbase << endl;    cout << oct << j << noshowbase << endl; } //Output 100 0x64 0144 100 64 144[/sourcecode]

Advertisements
  1. No comments yet.
  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: