×

C++ Programs

C++ Most popular & Searched Programs

C++ Basic I/O Programs

C++ Constructor & Destructor Programs

C++ Manipulators Programs

C++ Inheritance Programs

C++ Operator Overloading Programs

C++ File Handling Programs

C++ Bit Manipulation Programs

C++ Classes & Object Programs

C++ program to demonstrate example of setbase manipulator

Learn about the setbase manipulator in C++, and demonstrate the use of setbase manipulator using C++ program.
[Last updated : March 02, 2023]

setbase Manipulator in C++

The 'setbase' manipulator is used to change the base of a number to a different value.

This program will demonstrate example of setbase manipulator in c++ programming language.

setbase manipulator program in C++

/*C++ program to demonstrate example of 
setbase manipulator.*/

/*
setbase defines the base value of the value, 
in which you want to print the value, 
you can pass 8 for octal, 
10 for decimal and 16 for hexadecimal.
*/

#include <iostream>
#include <iomanip>
using namespace std;

/*
This program will show you to 
print decimal values in other format
*/

int main()
{
    int x = 12349;

    cout << "Octal       value is: " << setbase(8) << x << endl;
    cout << "Decimal     value is: " << setbase(10) << x << endl;
    cout << "Hexadecimal value is: " << setbase(16) << x << endl;

    return 0;
}

Output

Octal       value is: 30075
Decimal     value is: 12349
Hexadecimal value is: 303d

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.