C++ defines some format flags for standard input and output, which can be manipulated with the flags, setf, and unsetf functions. For example,
- cout.setf(ios_base::left, ios_base::adjustfield);
- void stream::unsetf(fmtflags flags);
The function unsetf() uses flags to clear the io_stream_format_flags associated with the current stream.
#include <iostream.h>
main()
{
ios_base::fmtflags original_flags = cout.flags();
cout<< 812<<‘|’;
cout.setf(ios_base::left,ios_base::adjustfield);
cout.width(10);
cout<< 813 << 815 << ‘\n’;
cout.unsetf(ios_base::adjustfield);
cout.precision(2);
cout.setf(ios_base::uppercase|ios_base::scientific);
cout << 831.0 << ‘ ‘ << 8e2;
cout.flags(original_flags);
}
Post Views: 8,616