Posted on

Three ways to set ioflags: (They are of type ios::fmtflags)

// First method
std::cout.setiosflags(std::ios::showbase);
std::cout << res;
// Second method
std::cout << std::setiosflags(ios::showbase) << res;

// Third method
std::cout << std::ios::showbase << res;

All the configurations are global.

Example

#include <iostream>
#include <iomanip> 
using namespace std;

int main() {
	int T; cin >> T;
	cout << setiosflags(ios::uppercase);
	cout << setw(0xf) << internal;
	while(T--) {
		double A; cin >> A;
		double B; cin >> B;
		double C; cin >> C;

		/* Enter your code here */
        cout << left << setiosflags(ios::showbase)  << resetiosflags(ios::uppercase)
            << setbase(16)
            << setw(0)
            << long(A) << endl;
        cout << right << showpos <<  resetiosflags(ios::showbase) << setbase(10) 
            << fixed << setprecision(2)  << setw(0xf) << setfill('_')
            << B << endl;
        cout << setprecision(9) << resetiosflags(ios::showpos) << scientific
            << setiosflags(ios::uppercase) 
            << C << endl;

	}
	return 0;

}

References

  1. http://www.cplusplus.com/reference/ios/ios_base/fmtflags/
  2. http://www.cplusplus.com/reference/iomanip/setiosflags/

Leave a Reply

Your email address will not be published. Required fields are marked *