iomanip setfill() function in C++ with Examples
The setfill() method of iomanip library in C++ is used to set the ios library fill character based on the character specified as the parameter to this method.
Syntax:
setfill(char c)
Parameters: This method accepts c as a parameter which is the character argument corresponding to which the fill is to be set.
Return Value: This method does not returns anything. It only acts as stream manipulators.
Example 1:
#include <iomanip>
#include <ios>
#include <iostream>
using namespace std;
int main()
{
int num = 50;
cout << "Before setting the fill char: \n"
<< setw(10);
cout << num << endl;
cout << "Setting the fill char"
<< " setfill to *: \n"
<< setfill( '*' )
<< setw(10);
cout << num << endl;
return 0;
}
|
Output:
Before setting the fill char:
50
Setting the fill char setfill to *:
********50
Example 2:
#include <iomanip>
#include <ios>
#include <iostream>
using namespace std;
int main()
{
int num = 50;
cout << "Before setting the fill char: \n"
<< setw(10);
cout << num << endl;
cout << "Setting the fill"
<< " char setfill to $: \n"
<< setfill( '$' )
<< setw(10);
cout << num << endl;
return 0;
}
|
Output:
Before setting the fill char:
50
Setting the fill char setfill to $:
$$$$$$$$50
Reference: http://www.cplusplus.com/reference/iomanip/setfill/
Last Updated :
22 Jul, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...