adding Precision Fill and Width parameters to Streams






This video tutorial explains how to use the width, precision and fill methods in c++ programming to set width fill and precision parameters.
You are gonna learn the syntax of width, precision, fill methods, how to use these methods in detail with examples.

source code for this tutorial

#include <iostream>

using namespace std;

int main()
{
    cout.precision(4);
    cout << 123.456<<endl;
    
    cout.width(10);
    cout << "hi"<<endl;
    
    cout.width(10);
    cout << 123.456<<endl;
    
    cout.fill('*');
    cout.width(10);
    
    cout << "hi"<<endl;
    cout.width(10);
    
    cout << 123.456<<endl;
    cout.setf(ios :: left);
    cout.width(10);
    cout << "hi"<<endl;
    
    cout.width(10);
    cout << 123.456<<endl;

return 0;
}

 
Back To Top