C++ ios Library - Showpoint Function


Advertisements

Description

It is used to sets the showpoint format flag for the str stream. When the showpoint format flag is set, the decimal point is always written for floating point values inserted into the stream (even for those whose decimal part is zero). Following the decimal point, as many digits as necessary are written to match the precision set for the stream (if any).

Declaration

Following is the declaration for std::showpoint function.

ios_base& showpoint (ios_base& str);

Parameters

str − Stream object whose format flag is affected.

Return Value

It returns Argument str.

Exceptions

Basic guarantee − if an exception is thrown, str is in a valid state.

Data races

It modifies str. Concurrent access to the same stream object may cause data races.

Example

In below example explains about std::showpoint function.

#include <iostream>

int main () {
   double a = 30;
   double b = 10000.0;
   double pi = 3.1416;
   std::cout.precision (5);
   std::cout <<   std::showpoint << a << '\t' << b << '\t' << pi << '\n';
   std::cout << std::noshowpoint << a << '\t' << b << '\t' << pi << '\n';
   return 0;
}

Let us compile and run the above program, this will produce the following result −

30.000  10000.  3.1416
30      10000   3.1416
ios.htm
Advertisements