Fill-function-in-C++ .

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


In some case when you will set the width of field , It is larger than given value on that case the unused position are filled with white space . However we can use the fill() to fill the unused position by desired character .


Fill() syntax

    cout.fill('*');
    

Where * is the desired character .


Example : Write a program that demonstrate the fill function .

    #include<iostream>
    using namespace std;
    int main()
    {  
         cout.fill('*');
         cout.width(8);
         cout<<1234
         return 0;
    }
    
    OUTPUT : ****1234
           

The above program we have specify * character in fill() . Which is fill the first four position with * .


Welcome to AndroidATPoint.

back image                     next image