S
subramanian100in
Suppose I have a program which uses 'ostream' type as the parameter
type for a function and 'cout' object for writing into the standard
output. Following is my understanding regarding, which headers to
#include for this scenario.
Since the program uses 'cout' object, I have to #include <iostream>
header for 'cout'. In the ISO/IEC-14882:2003 document, in page 608, in
section 27.3 - Standard iostream objects, the synopsis for the header
<iostream> mentions the following line(apart from other statements):
extern ostream cout;
From the above statement, since 'cout' is mentioned for <iostream>,
#including <iostream> is sufficient for using 'cout' object in my
program. Moreover, since 'ostream' is also mentioned in the same
statement, the forward declaraion of 'ostream' type should also be
known in the <iostream> header. This means that I need NOT #include
<iosfwd>. Is this
correct ? Since the class definition of the type 'ostream' is
needed(because the function parameter type is 'ostream&'), I HAVE to
#include <ostream> header instead of relying on the particular
compiler implementation #including the <ostream> inside <iostream>.
So, for the scenario mentioned in the beginning, I need ONLY to
#include
#include <iostream>
#include <ostream>
// ...
using namespace std;
I have NOT #included <iosfwd> header.
Is the above understanding of mine is correct ?
Correct me wherever I am wrong.
Kindly explain.
Thanks
V.Subramanian
type for a function and 'cout' object for writing into the standard
output. Following is my understanding regarding, which headers to
#include for this scenario.
Since the program uses 'cout' object, I have to #include <iostream>
header for 'cout'. In the ISO/IEC-14882:2003 document, in page 608, in
section 27.3 - Standard iostream objects, the synopsis for the header
<iostream> mentions the following line(apart from other statements):
extern ostream cout;
From the above statement, since 'cout' is mentioned for <iostream>,
#including <iostream> is sufficient for using 'cout' object in my
program. Moreover, since 'ostream' is also mentioned in the same
statement, the forward declaraion of 'ostream' type should also be
known in the <iostream> header. This means that I need NOT #include
<iosfwd>. Is this
correct ? Since the class definition of the type 'ostream' is
needed(because the function parameter type is 'ostream&'), I HAVE to
#include <ostream> header instead of relying on the particular
compiler implementation #including the <ostream> inside <iostream>.
So, for the scenario mentioned in the beginning, I need ONLY to
#include
#include <iostream>
#include <ostream>
// ...
using namespace std;
I have NOT #included <iosfwd> header.
Is the above understanding of mine is correct ?
Correct me wherever I am wrong.
Kindly explain.
Thanks
V.Subramanian