width-function-in-C++ .

In this session i have discuss width function in C++ .


The width() function is used to define the width of field . It is a member function .

Width() syntax

    cout.width(w);
    

Where w is number of columns .


Example : Write a program that demonstrate the width function .

    #include<iostream>
    using namespace std;
    int main()
    {  
          cout.width(5);
          cout<<456;
          return 0;
    }
    
    OUTPUT : 456
           

The above program create the five columns and assign the value to right side to left side . It will left two columns from left side because there is only three digit value .


Welcome to AndroidATPoint.

back image                     next image