C++ fill( ) function














































C++ fill( ) function



DESCRIPTION: 

It is used to get/set fill character. The fill character is the character used by output insertion functions to fill spaces when padding results to the field width.


Declaration:  

get (1)	 char fill() const;
set (2) char fill (char fillch);

Parameters:     

fillch - The new fill character.

 

Return Value:

The value of the fill character before the call.

 

Program:

 

#include <iostream>     
using namespace std;
int main () {
char prev;

std
::cout.width (10);
std
::cout << 40 << '\n';

prev
= std::cout.fill ('x');
std
::cout.width (10);
std
::cout << 40 << '\n';

std
::cout.fill(prev);

return 0;
}

Output:

40

xxxxxxxx40


Comments