Formatting integer values - C++ Data Type

C++ examples for Data Type:int

Description

Formatting integer values

Demo Code

#include <iostream>
#include <iomanip>
#include <cmath>                       // For square root function
using std::cout;//w  ww. j av  a  2 s. com

int main()
{
    int a{16}, b{66};
    cout << std::setw(5) << a << std::setw(5) << b << std::endl;
    cout << std::left << std::setw(5) << a << std::setw(5) << b << std::endl;
    cout << " a = " << std::setbase(16) << std::setw(6) << std::showbase << a
         << " b = " << std::setw(6) << b << std::endl;
    cout << std::setw(10) << a << std::setw(10) << b << std::endl;
}

Result


Related Tutorials