Using cout.fill() in C++

By: Jagan Emailed: 1677 times Printed: 2158 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Normally cout fills the empty field created by a call to width() with spaces, as shown above. At times you may want to fill the area with other characters, such as asterisks. To do this, you call fill() and pass in as a parameter the character you want used as a fill character. Listing below illustrates this.

Using fill().

1:     // fill()
2:
3:     #include <iostream.h>
4:
5:     int main()
6:     {
7:        cout << "Start >";
8:        cout.width(25);
9:        cout << 123 << "< End\n";
10:
11:
12:        cout << "Start >";
13:       cout.width(25);
14:       cout.fill(`*');
15:       cout << 123 << "< End\n";
16:     return 0;
17: }

Output: Start >                  123< End
Start >******************123< End

Analysis: Lines 7-9 repeat the functionality from the previous example. Lines 12-15 repeat this again, but this time, on line 14, the fill character is set to asterisks, as reflected in the output.


C++ Home | All C++ Tutorials | Latest C++ Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(1)


1. View Comment

Great! Thanks :)

View Tutorial          By: Shivang at 2010-10-10 11:53:54

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Jagan
Importing a Certificate for the CA example using keytool in Java
The if-then-else Statement in Java
WHERE Clauses in SQL
The TryCatchFinally Interface in JSP
assert() Function Example program in C
Guidelines for Struts Application Development
Using printf function in C
File Inclusion in C
Using Multiple Message Resource Bundles in Struts
While and For Loops in C
Arrays sample program in C
Controlling Page Navigation in JSF - Static and Dynamic Navigation
Using cout.fill() in C++
Types of Profiles in J2ME
DateField sample program in J2ME

More Tutorials in C++
Two-Dimensional Array Manipulation in C++
Calculate average using Two-Dimensional Array in C++
Compute the square root of the sum of the squares of an array in C++
Matrix using nested for loops in C++
Sorting an array of Strings in C++
Calculating total based on the given quantity and price in C++
Compiling and Linking Multiple Source Files in C++
Enumerations in C++
Program to add two numbers in C++
Comments in C++
while loop in C++
for loop in C++
Programming errors a compiler will detect in C++
if in C++
Using the Built-in Arithmetic Types in C++

More Latest News
Most Viewed Articles (in C++ )
Dot (.) vs Arrow (->) to access data members in C++
Using cout.width() in C++
Calculating total based on the given quantity and price in C++
assert() example program in C++
Public versus Private members in C++
Calculate average using Two-Dimensional Array in C++
Difference between Procedural, Structured, and Object-Oriented Programming
C++ Recursion function explained using Fibonacci series
Sorting an array of Strings in C++
Constructors and Destructors in C++
Reverse a String in C++
Matrix using nested for loops in C++
Using cout in C++
Demonstration of Prefix and Postfix operators in C++
Using cout.fill() in C++
Most Emailed Articles (in C++)
Looping with the keyword goto in C++
Difference between Procedural, Structured, and Object-Oriented Programming
Operator Precedence in C++
Using peek() and putback() with cin in C++
Function overloading in C++
Default arguments in C++
Lvalues and Rvalues in C++
Compiling and Linking Multiple Source Files in C++
C++ and Object-Oriented Programming
Getting Started with C++
Tutorial on Classes and Members in C++
Public versus Private members in C++
for Loops in C++
Using switch Statements in C++
How to handle Exceptions in C++