Format Flags for Use with setiosflags() - C++ Language Basics

C++ examples for Language Basics:Console

Introduction

Flag Meaning
ios::fixedAlways show the decimal point with six digits after the decimal point. This flag takes precedence if it's set with the ios::showpoint flag.
ios::scientific Use exponential display in the output.
ios::showpointAlways display a decimal point and six significant digits total.
ios::showpos Display a leading + sign when the number is positive.
ios::left Left-justify the output.
ios::rightRight-justify the output.

To combine the flags.

cout << setiosflags(ios::dec | ios::fixed | ios::showpoint); 

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;
int main()//from   w w w.  ja v  a 2s.  c  o  m
{
   cout << "|" << 5 <<"|";
   cout << "|" << setw(4) << 5 << "|";
   cout << "|" << setw(4) << 56829 << "|";
   cout << "|" << setw(5)  << setiosflags(ios::fixed) << setprecision(2)  << 5.26 << "|";
   cout << "|" << setw(5)  << setiosflags(ios::fixed) << setprecision(2)  << 5.267 << "|";
   cout << "|" << setw(5)  << setiosflags(ios::fixed) << setprecision(2)  << 53.264 << "|";
   cout << "|" << setw(5)  << setiosflags(ios::fixed) << setprecision(2)  << 534.264 << "|";
   cout << "|" << setw(5)  << setiosflags(ios::fixed) << setprecision(2)  << 534. << "|";
   return 0;
}

Result


Related Tutorials