Reputation: 11
why setprecision and fixed and other iomanip functions called by using cout not like the string functions for example name.find('') plz help
Upvotes: 1
Views: 98
Reputation: 19052
They allow you to chain the operations in the manner:
cout << setprecision(3) << 1.234 << setprecision(4) << 3.45678;
In fact, there are functions to do that, but using them directly breaks this "streaming" capability:
cout.precision(3);
cout << 1.234;
cout.precision(4);
cout << 3.45678;
See: https://en.cppreference.com/w/cpp/io/manip/setprecision vs https://en.cppreference.com/w/cpp/io/ios_base/precision
Upvotes: 1