Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios::base:precision & setprecision

Tags:

c++

What is the difference between ios::base:precision & setprecision Given in the following links? http://www.cplusplus.com/reference/ios/ios_base/precision/

http://www.cplusplus.com/reference/iomanip/setprecision/

like image 584
Rizvi Avatar asked Oct 18 '25 20:10

Rizvi


1 Answers

The difference it to do with the usage. The first (setter) is a member function, so gets called like this:

std::cout.precision(10);

The second isn't a member function so is called different.

std::cout << std::setprecision(10);

The 2nd link explicitly says

"Behaves as if member precision were called with n as argument on the stream on which it is inserted/extracted as a manipulator "

like image 159
doctorlove Avatar answered Oct 20 '25 09:10

doctorlove



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!