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

Template class and class template in c++, Differentiate between a template ...

Differentiate between a template class and class template in C++? Ans) Template class: A generic definition or a parameterized class not instantiated until the client gives the

Object Oriented Programming, Ask queCreate an object oriented application w...

Ask queCreate an object oriented application with C# that computes the area of a rectangle, and the area and the volume of a cuboid. Based on the inheritance concept, create a bas

Decode the code, smugglers transfer the messages from one to another by usi...

smugglers transfer the messages from one to another by using the mobile

C program to maintain database of employees, Aim: To implement a program t...

Aim: To implement a program to maintain information of employees in an educational institute using inheritance. Code:                       class staff {

Why php is sometimes called as embedded scripting language, Why PHP is some...

Why PHP is sometimes called as embedded scripting language? PHP is a high level language that is used to allow users to write and understand it in human readable form and also

Area, find area uder the curve y=f(x) between x=a and x=b   #incl...

find area uder the curve y=f(x) between x=a and x=b   #include float start_point, /* GLOBAL VARIABLES */ end_point, total_area; in

Decode the code, Smugglers are becoming very smart day by day. Now they hav...

Smugglers are becoming very smart day by day. Now they have developed a new technique of sending their messages from one smuggler to another. In their new technology, they are send

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