Newbie help needed on "IOStream.h" vs "IOstream", namespaces etc.

  • Thread starter as mellow as a horse
  • Start date
A

as mellow as a horse

I'm not new to C++, but it has been a while, and I'm defintely new to dot
net.

So to get back into the swing of things, I tried to create the ubiqitous
"hello world" program using a console application. Most of the C++
programming I've ever done has been in Borland products (mostly C++ Builder)
and all I ever needed to do a "hello world" was include "iostream.h".

But when I do that in dot net, I get a fatal error saying file not found.
After much searching through online help, I find I have to drop the "h" and
just include "iostream". But when I did that I found my cout line was
causing an error. After much more searching through help files, I discover
I have to qualify cout with a namespace i.e. "std::cout" or use a "using
namespace std" directive. I've never used namespaces in C++ before,
although I'm aware of them through dabbling in XML.

So all works well, but then I find that namespaces only apply to "iostream"
and I can use "iostream.h" to avoid having to use them. So my question is
(at last!):

How do I include "iostream.h" when dot net can't/won't find it, and should I
be doing so anyway i.e. is it the done thing now to use namespaces
everywhere and thus only use iostream?
 
W

William DePalo [MVP VC++]

as mellow as a horse said:
I'm not new to C++, but it has been a while, and I'm defintely new to dot
net.
Roger.

So to get back into the swing of things, I tried to create the ubiqitous
"hello world" program using a console application. Most of the C++
programming I've ever done has been in Borland products (mostly C++ Builder)
and all I ever needed to do a "hello world" was include "iostream.h".

The problem here is not with .Net per se but with the changes in ISO
standard C++. VS' compiler, per the standard, no longer supports
How do I include "iostream.h" when dot net can't/won't find it,
and should I be doing so anyway
Nope.

i.e. is it the done thing now to use namespaces
everywhere and thus only use iostream?

Many people use

using namespace std;

in source (not in header!!!!)

others will fully qualify names, e.g,

std::cout

You probably want to check a good text like ones from Herb Sutter for the
gory details, stylistic and otherwise.

Regards,
Will
 
C

Carl Daniel [VC++ MVP]

as said:
How do I include "iostream.h" when dot net can't/won't find it, and
should I be doing so anyway i.e. is it the done thing now to use
namespaces everywhere and thus only use iostream?

To expand on Will's statements a bit -

<iostream.h> is the main header file for "classic" or "pre-standard"
IOStreams, as originally produced by AT&T. <iostream> is the main header
file for "standard" IOStreams, as standardized in the C++ standard (ISO
14882:1998) some six years ago.

VC6 supported <iostream.h> well and <iostream> poorly (VC6 was finalized
before the C++ standard was finished). VC7 supported both systems, but
began to flag the older pre-standard streams as "deprecated". VC7.1, aka
VS.NET 2003 dropped support for pre-standard streams altogether.

In many cases, all you need to do is drop the .h and add a using
declaration, or qualify references to the names. But there are other
differences - for example, pre-standard streams let you specify the sharing
mode when opening a file with an fstream. Standard iostreams have no
concept of file sharing modes, so if you need that kind of control, you have
to use vendor-specific extensions for support.

There were other (more drastic) changes made to the basic hierarchy of
streams classes, including most significantly, the fact that (nearly) all of
the streams classes are now templates, parameterized on the type of
character you're using (char or wchar_t).

If you're interested in the gorey details, the book "Standard IOStreams and
Locales" by Angelika Langer and Klaus Kreft is the authoritative work on the
subject.

-cd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top