Using showpoint (setf(ios::showpoint)) in controlling the trailing zeroes and floating points for standard output in C++ programming

 

Compiler: Visual C++ Express Edition 2005

Compiled on Platform: Windows XP Pro SP2

Header file: Standard

Additional library: none/default

Additional project setting: Set project to be compiled as C++

Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)

Other info: none

To do: Using showpoint (setf(ios::showpoint)) in controlling the trailing zeroes and floating points for standard output in C++ programming

To show: How to use setf(ios::showpoint) to control the trailing zeroes and floating points for standard output in C++ programming

 

// using showpoint in controlling the trailing zeroes and floating points

#include <iostream>

#include <iomanip>

using namespace std;

 

void main(void)

{

cout<<"Before using the ios::showpoint flag\n"

<<"------------------------------------"<<endl;

cout<<"cout prints 88.88000 as: "<<88.88000

<<"\ncout prints 88.80000 as: "<<88.80000

<<"\ncout prints 88.00000 as: "<<88.00000

<<"\n\nAfter using the ios::showpoint flag\n"

<<"-----------------------------------"<<endl;

cout.setf(ios::showpoint);

cout<<"cout prints 88.88000 as: "<<88.88000

<<"\ncout prints 88.80000 as: "<<88.80000

<<"\ncout prints 88.00000 as: "<<88.00000<<endl;

 

return;

}

 

Output example:

 

Before using the ios::showpoint flag

------------------------------------

cout prints 88.88000 as: 88.88

cout prints 88.80000 as: 88.8

cout prints 88.00000 as: 88

After using the ios::showpoint flag

-----------------------------------

cout prints 88.88000 as: 88.8800

cout prints 88.80000 as: 88.8000

cout prints 88.00000 as: 88.0000

Press any key to continue . . .

 

 

C and C++ Programming Resources | C & C++ Code Example Index