Using ios::showbase to print integers in hexadecimal and octal base number C++ program example

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Using ios::showbase to print integers in hexadecimal and octal base number in C++ programming

To show: How to use ios::showbase to print integer in hexadecimal and octal numbering base in C++ programming

 

// using the ios::showbase

#include <iostream>

#include <iomanip>

using namespace std;

 

void main(void)

{

long p = 2000;

 

cout<<setiosflags(ios::showbase)

<<"Printing integers by their base:\n"

<<"--------------------------------\n"

<<"Decimal ---> "<<p<<"\n"

<<"Hexadecimal---> "<<hex<<p<<"\n"

<<"Octal ---> "<<oct<<p<<endl;

}

 

Output example:

 

Printing integers by their base:

--------------------------------

Decimal ---> 2000

Hexadecimal---> 0x7d0

Octal ---> 03720

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index