CodeClerks

Defining Field Width With width() Function In C++



Write the reason you're deleting this FAQ

Defining Field Width With width() Function In C++

Wecan use the width() function todefine the width of a field necessary for the output of an item. Since, it is a
member function; we have to use an object to invoke it, as shown below:


cout.width(w);

Wherew is the field width (number of columns). The output will be printed in a field
of w characters wide at the right end of the field. The width() function can specify the field width for only one item (theitem that follows immediately). After printing one item (as per the
specifications) it will revert back to the default. For example, The statements

cout.width(5);

cout

Comments

Please login or sign up to leave a comment

Join