setf method for left and right alignment in a display field
Use of setf method of cout to align content as left or right in a display field.
- Learning setf to align content within there fields in a left and right aligned fashion.
- Learning to unset the alignment formatting.
- Learning the persistent bahaviour of setf method.
This include file is required for all IO manipulation for display purposes.
This string will be used for display
This will set format for all subsequent display fields to aligned left in there field area. By default the content is aligned to right in its respective field area.
Hello will be printed twice with both field set to size of 10 and content aligned to left. Notice that setf is persistent in nature and it is not required to be set again and again for every field.
Since setf is persistent in nature we need to unset it to come to normal default status.
This will print the content as default way of fitting content towards the right of the given field width.
This is done for right alignment of content. This is useful when tabulated entry has to be printed.
This will print the content in right aligned form.
- Commonly learners forget to set has a persistent behaviour unlike setw.
Suggested Filename(s): setwsetf.cpp
sunmitra| Created: 15-May-2018 | Updated: 15-Sep-2018|