C++ cout Formatting integer values

Description

C++ cout Formatting integer values

#include <iostream>
#include <cmath>                       // For square root function
using std::cout;//from  ww w  .  j  av  a2s  .c  o m

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;
}



PreviousNext

Related