iomanip setfill() function in C++ with Examples
The setfill() method of iomaip 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:
// C++ code to demonstrate // the working of setfill() function #include <iomanip> #include <ios> #include <iostream> using namespace std; int main() { // Initializing the integer int num = 50; cout << "Before setting the fill char: \n" << setw(10); cout << num << endl; // Using setfill() cout << "Setting the fill char" << " setfill to *: \n" << setfill('*') << setw(10); cout << num << endl; return 0; } |
Before setting the fill char:
50
Setting the fill char setfill to *:
********50
Example 2:
// C++ code to demonstrate // the working of setfill() function #include <iomanip> #include <ios> #include <iostream> using namespace std; int main() { // Initializing the integer 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; } |
Before setting the fill char:
50
Setting the fill char setfill to $:
$$$$$$$$50
Reference: http://www.cplusplus.com/reference/iomanip/setfill/
Recommended Posts:
- iomanip resetiosflags() function in C++ with Examples
- iomanip setbase() function in C++ with Examples
- iomanip setiosflags() function in C++ with Examples
- iomanip setw() function in C++ with Examples
- iomanip setpricision() function in C++ with Examples
- std::setbase, std::setw , std::setfill in C++
- ios eof() function in C++ with Examples
- ios bad() function in C++ with Examples
- ios clear() function in C++ with Examples
- fill() function in C++ STL with examples
- ios fail() function in C++ with Examples
- fill_n() function in C++ STL with examples
- ios setstate() function in C++ with Examples
- wcscmp() function in C++ with Examples
- ios operator() function in C++11 with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



