The hex, oct, dec numbering base system and setbase() stream manipulator C++ code 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 the hex, oct, dec numbering base system and setbase() stream manipulator in C++ programming
To show: How to use the hex, oct, dec numbering base system and setbase() stream manipulator in C++ programming
// using hex, oct, dec and setbase stream manipulator
#include <iostream>
#include <iomanip>
using namespace std;
void main(void)
{
int p;
cout<<"Enter a decimal number:"<<endl>>p;
cout<<p<< " in hexadecimal is: "
<<hex<<p<<'\n'
<<dec<<p<<" in octal is: "
<<oct<<p<<'\n'
<<setbase(10) <<p<<" in decimal is: "
<<p<<endl;
cout<<endl;
}
Output example:
Enter a decimal number:
100
100 in hexadecimal is: 64
100 in octal is: 144
100 in decimal is: 100
Press any key to continue . . .