Dec 13, 2011

Program : Use Setw() Function

Program : Use Setw() Function

The setw() function is used to set the field width of the output data. For using setw() we have to use iomanip header file. In bracket that of setw we have to write integer value according to output to be shown.



Let see following program to better understand :-

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
int main()
{


cout << "HELLO" << setw(7) << "World" ; 

/* cout for display data on screen it Shows HELLO  World, After Hello, their is one space as i gave and World is of 5 character and we set width of 7 it means we get 7 columns and we have to fill with that data here World so Output is HELLO<space><space>World. Their is two space after HELLO because we give width = 7 and 5 are filled and two are filled with space & it start from Right. */




getch();

return 0;
}






11 comments:

  1. fantastic and excellent programming, and the way you explained the setw() is so excellent;
    thanks

    ReplyDelete
  2. Thanks very much Admin !

    ReplyDelete
  3. excellent way of teaching
    i tried many websites but could not understand anything.
    This is the BEST place to learn programming

    ReplyDelete
  4. Excellent teaching way .Looking forward to know more about this type of solution .than you

    ReplyDelete
  5. lol its easy to learn here, thanks for it,.!

    ReplyDelete
  6. Thank you so much... Love the way you explain.. keep up the good work

    ReplyDelete