Explain the changing field width, C/C++ Programming

Assignment Help:

Changing Field width

The printf() and scanf() functions from the standard library, use width specifier for controlling the width of its output . Similarly, the ostream class also has a member function width() for the same. This function has the following prototype.

                int width(void);

                int width(int newsize);

The first form returns the current field width. The default is always zero. That is because, the cout object always uses space just wide enough to output the values and a default size if zero matches all. The second form can be used to alter the current width setting. The argument passed to it is the new width to be set. It also returns the previous width. The width () function affects only the next item displayed. The filed width reverts to default afterwards.

e.g.

                void main()

                 {

                                cout<<" default width="<< cout.width()<

                                cout<<"[";

                                cout.width(10);                                 Set width to 10

                                cout<<"A";

                                cout<<"]";

                }

 


Related Discussions:- Explain the changing field width

Declaring Integer variables with an example, How do you declare an integer ...

How do you declare an integer variable? Explain with an example.

Operators, write a program to accept ten numbers and display the total

write a program to accept ten numbers and display the total

Explain the command line parameters, Explain the Command Line Parameters? ...

Explain the Command Line Parameters? The Command line arguments are parameters supplied to a program from the operating system. These arguments are parameters accepted to main

Fibonacci series, draw the flow chart to print the fibonacci series upto n ...

draw the flow chart to print the fibonacci series upto n th terms

Explain destructors, Destructors A destructor function gets implemented...

Destructors A destructor function gets implemented whenever an instance of the class to which it belongs goes out of existence. The primary usage of a destructor function is

All topics in c, Give practice in writing program''s..

Give practice in writing program''s..

Padovan.., count the number of string in n-th padovan string

count the number of string in n-th padovan string

Constructor , How can I handle a constructor that fails?

How can I handle a constructor that fails?

Create complex number using constructor , Create Complex number using const...

Create Complex number using constructor: class complex                                 {                                                   private:

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd