C++ Manipulator scientificC++ manipulator scientific function is used to set the floatfield format flag for the str stream to scientific. When we set floatfield to scientific, then floating point values are written using scientific notation; the value is represented always with only one digit before the decimal point, followed by the decimal point and like many decimal digits as the precision field. And finally, this notation always includes an exponential part consisting on the letter e followed by an optional sign and three exponential digits. C++98 The floatfield format flag is a selective and a toggle flag: it can take one, both or none of the following values as given below -
C++11 The floatfield format flag is a selective and a toggle flag: it can take any of the following values, or none as given below -
SyntaxParameterstr: stream object whose format flag is affected. Return valueIt returns argument str. Data RacesData races may cause when modifies str concurrent access to the same stream object. Exceptionsstr is in a valid state, if an exception is thrown. Example 1Let's see the simple example to demonstrate the use of scientific manipulator: Output: The number 0.01 in fixed: 0.010000 The number 0.01 in scientific: 1.000000e-02 The number 0.01 in hexfloat: 0x1.47ae147ae147bp-7 The number 0.01 in default: 0.01 Parsing 0x1P-1022 as hex gives 0 Example 2Let's see another simple example: Output: default: 3.1416 2006 1e-10 fixed: 3.14159 2006.00000 0.00000 scientific: 3.14159e+00 2.00600e+03 1.00000e-10 Example 3Let's see another simple example: Output: The number 0.01 in fixed: 0.010000 The number 0.01 in scientific: 1.000000e-02 The number 0.01 in hexfloat: 0x1.47ae147ae147bp-7 The number 0.01 in default: 0.01 Parsing 0x1P-1022 as hex gives 0
Next TopicC++ Manipulator
|