Mail Archives: djgpp/1999/11/15/15:32:42
In article <38301C64 DOT B476CAC0 AT nortelnetworks DOT com>,
Ian Chapman <ichapman AT nortelnetworks DOT com> wrote:
>Mumit,
> I'm not at all able to see what the issue is. cout works like any text
>book will tell you. I did not know that you could get away with out
>the *.h in the include bit. Wonder why? and what digs with this std?
>I'm not learning from you, I'm sure that you can be more enlightening
>rather than coming through as a smartie.
[ Ian, if you've also posted a note as well as emailing it, please do
mention that in the email. Save me some typing. ]
The issue is quite simple: All of iostreams live in the std namespace,
and unless you specifically (1) qualify explicitly, or (2) import
specific symbols or all the symbols from the std namespace, you're not
allowed to use cout, cerr, etc.
Here's an example of (1):
#include <iostream>
int
main ()
{
std::cout << "Hello world" << std::endl;
}
Here's an example of (2.a):
#include <iostream>
using std::cout;
using std::endl;
int
main ()
{
cout << "Hello world" << endl;
}
Here's an example of (2.b):
#include <iostream>
using namespace std;
int
main ()
{
cout << "Hello world" << endl;
}
Some vendors have chosen to use headers with .h suffix as a backward
compatibility header; eg., if you include <iostream.h>, it will
implicitly do a `using namespace std;' for you, or put all the names
in the global namespace. However, this is by no means standard, but
it just a convention used by some of the vendors.
Newer books such as Stroustrup 3rd and a few others cover this in some
detail.
Regards,
Mumit
- Raw text -