0

I declared a float variable, say a, then I assigned 57.00 to it. When I wanted to print the 'a' using cout object, the stream seemed to print only 57 without the decimal point.

So, the solution to making the decimal point printed is adding showpoint manipulator after cout. Example: cout << showpoint << fixed << setprecision(2) << a << endl;

The function setprecision here is used together with fixed to specify the number of digits to be printed after the decimal point. After googling for a while, I found that showpoint and fixed are a part of <ios> header file.

So, why don't we have to import this header? Without importing it, the code worked just fine. And importing <iostream> is all I need to make these stream manipulators worked as intended.

Is <ios> header automatically imported whenever and wherever the <iostream> header is imported?

Sat_34
  • 3
  • 3
  • 1
    First hit on Google: " Including this header may automatically include other headers, such as , , , and/or ." Note the "may" though, I'd still use the import, if just for code clarity. – Maarten Bodewes Jan 02 '23 at 02:28
  • 1
    For reference, see Cppreference's page for the [``](https://en.cppreference.com/w/cpp/header/iostream) standard library header. There, under the Includes section, you'll see that `` is included. The C++ standard guarantees that, see [`[iostream.syn]`](https://eel.is/c++draft/iostream.syn) in the current draft. See also this question: [Which headers in the C++ standard library are guaranteed to include another header?](https://stackoverflow.com/q/26614983/1458097) – heap underrun Jan 02 '23 at 02:40

0 Answers0