iostream.h with ms visual c++ 6.0?

  • Thread starter Moritz Steinberger
  • Start date
M

Moritz Steinberger

Hello,

I want to use a tutorial to take first steps. I use MS Visual c++ 6.0 and
Win 98. When I try to compile a "hello world" program using the <iostream.h>
library and cout << "hello world", the compiler tells me that "cout" is an
undeclared identifier. But it does not tell me that including iostream.h
causes any problems. I read in a german newsgroup that instead of
<iostrem.h>, simply <iostrem> has to be included under MS Visual C++ and
that std::cout must be used. But when I try this, the compiler says
referring to #include <iostream>: "eh.h is only for C++". What should I do?

thank you very much in advance,

Moritz
 
J

Jeff Flinn

Moritz Steinberger said:
Hello,

I want to use a tutorial to take first steps. I use MS Visual c++ 6.0 and
Win 98. When I try to compile a "hello world" program using the
library and cout << "hello world", the compiler tells me that "cout" is an
undeclared identifier. But it does not tell me that including iostream.h
causes any problems. I read in a german newsgroup that instead of
<iostrem.h>, simply <iostrem> has to be included under MS Visual C++ and
that std::cout must be used. But when I try this, the compiler says
referring to #include <iostream>: "eh.h is only for C++". What should I
do?

If your source code file ends with .c it is compled as "C" code and not
"C++", use .cpp as the file extension to compile as "C++". Or configure VC
to work the way you prefere.

#include <iostream> is the proper C++ form. Also remember cout is in
namespace std. So you will need to std::cout.

Jeff F
 
J

John Harrison

Moritz Steinberger said:
Hello,

I want to use a tutorial to take first steps. I use MS Visual c++ 6.0 and
Win 98. When I try to compile a "hello world" program using the
library and cout << "hello world", the compiler tells me that "cout" is an
undeclared identifier. But it does not tell me that including iostream.h
causes any problems. I read in a german newsgroup that instead of
<iostrem.h>, simply <iostrem> has to be included under MS Visual C++ and
that std::cout must be used. But when I try this, the compiler says
referring to #include <iostream>: "eh.h is only for C++". What should I do?

thank you very much in advance,

Moritz

Make sure you're filename is called something.cpp. It sounds like you are
invoking the C compiler not the C++ compiler.

The advice about <iostream> or <iostream.h> is true of all compilers. Only
<iostream> is correct C++.

john
 
C

Christoph Rabel

Moritz said:
I want to use a tutorial to take first steps. I use MS Visual c++ 6.0 and
Win 98. When I try to compile a "hello world" program using the <iostream.h>
library and cout << "hello world", the compiler tells me that "cout" is an
undeclared identifier. But it does not tell me that including iostream.h
causes any problems. I read in a german newsgroup that instead of
<iostrem.h>, simply <iostrem> has to be included under MS Visual C++ and

iostream.h is an old header that should not be used anymore.
Please do as suggested in that newsgroup.

Also, you might want to get a good book to learn C++.
"Accelerated C++" is very recommended for starters.
that std::cout must be used. But when I try this, the compiler says
referring to #include <iostream>: "eh.h is only for C++". What should I do?

Your question is offtopic here, because you have problems
with a particular compiler, not the language itself.

Please ask compilerspecific questions in the appropriate
NGs, e.g. microsoft.public.de.vc (A german ng dedicated to VC++)


Nonetheless, your problem arises because you have named your
sourcefile .c the compiler thinks you want to program in C.

So simply rename your sourcefile to .cpp and it should work.

hth

Christoph
 
M

Moritz Steinberger

Hello,
Please do as suggested in that newsgroup.

I did as Mr. Harrison and Mr. Flinn told me here and it works fine now.
Thank you, Mr. Rabel, Mr. Harrison and Mr. Flinn.
Also, you might want to get a good book to learn C++.
"Accelerated C++" is very recommended for starters.

Well I checked several books, one even called "C++ for dummies", but I seem
to be even too dummy-like for the latter. Then I found a tutorial on www.
cplusplus.com which I would like to recommend to anyone who is an absolute
beginner or who knows such people and wants to give them some advice.
Your question is offtopic here, because you have problems
with a particular compiler, not the language itself.

I'm sorry for that, I just didn't realize the differences between C, C++ and
the Microsoft Visual C++ compiler.
Please ask compilerspecific questions in the appropriate
NGs, e.g. microsoft.public.de.vc (A german ng dedicated to VC++)

I'll do so in the future, thank you.

Moritz
 
K

KTC

Moritz Steinberger said:
Well I checked several books, one even called "C++ for dummies",
but I seem to be even too dummy-like for the latter. Then I
found a tutorial on www.cplusplus.com which I would like to
recommend to anyone who is an absolute beginner or who knows
such people and wants to give them some advice.

DON'T try to learn C++ from "C++ for dummies", it would do you more
harm than good (if it does you any good at all...).

The tutorial down at cplusplus.com is quite good EXCEPT for the fact
that it doesn't use the correct header name of <iostream> and instead
use <iostream.h> which as have already been said is wrong.

The only tutorial I can find on the internet that even use the
correct header is http://cplus.about.com/library/blcplustut.htm . It
seems quite good to me although some good books is still recommanded
as the way to learn.

Take a look at http://www.accu.org/bookreviews/public/index.htm for
some books review.


KTC
 
J

Julie

Your question is offtopic here, because you have problems
with a particular compiler, not the language itself.

I'm trying to figure out why this question is off topic here?

1) The extensionless headers is (in my opinion) a very poor decision on the
standards committee. Originally, before standardized, the headers *DID* have a
..h extension, and library implementors based their headers on that fact. Then,
the committee later changed to extensionless (if I recall correctly, it was
originally a mistake/unintended omission, but no one on the committee made
enough of a fuss about it, so it just stayed).

Other than Apple operating systems, I'm not aware of any os that doesn't use an
extensions to identify file types, although I'll be first to admit that my os
experience is primarily limited to the os that is found on 90% of desktop
systems.

The extension/extensionless issue is something that isn't compiler specific,
but is negative fallout of the slow standardization process that plagued C++
during the 90s.

2) All C++ compilers I've ever used (maybe 5), have defaulted to compiling C
code for .c files and C++ for .cpp files. Again, I don't think that this issue
is compiler-specific in any way.
 
J

John Harrison

1) The extensionless headers is (in my opinion) a very poor decision on the
standards committee. Originally, before standardized, the headers *DID* have a
.h extension, and library implementors based their headers on that fact. Then,
the committee later changed to extensionless (if I recall correctly, it was
originally a mistake/unintended omission, but no one on the committee made
enough of a fuss about it, so it just stayed).

Really, where do you recall this from? I'm not doubting you, just interested
in your source of information.

john
 
J

Julie

Really, where do you recall this from? I'm not doubting you, just interested
in your source of information.

Feel free to doubt -- I'm going from memory on this one from about 8 years ago,
and I can barely remember my name day to day...

I can't remember where I heard it -- I just know at the time that I first heard
about extensionless headers, I thought it was a bad idea and tried to find out
the motivation. I just did a quick search on Google and couldn't turn up
anything. Perhaps someone that remembers better than I can either confirm/deny
my thought on the subject...
 
P

P.J. Plauger

Julie said:
I'm trying to figure out why this question is off topic here?

1) The extensionless headers is (in my opinion) a very poor decision on the
standards committee. Originally, before standardized, the headers *DID* have a
.h extension, and library implementors based their headers on that fact. Then,
the committee later changed to extensionless (if I recall correctly, it was
originally a mistake/unintended omission, but no one on the committee made
enough of a fuss about it, so it just stayed).

Hardly. It was a concerted decision by the Library Subgroup that I opposed
vehemently. It certainly didn't happen by accident. I don't much care for
it to this day, but it's what the committee decided on, so it's Standard
C++ now.
Other than Apple operating systems, I'm not aware of any os that doesn't use an
extensions to identify file types, although I'll be first to admit that my os
experience is primarily limited to the os that is found on 90% of desktop
systems.

The extension/extensionless issue is something that isn't compiler specific,
but is negative fallout of the slow standardization process that plagued C++
during the 90s.

I don't see how the slowness of the process caused this particular decision.
It's not like the extensions withered on the vine...
2) All C++ compilers I've ever used (maybe 5), have defaulted to compiling C
code for .c files and C++ for .cpp files. Again, I don't think that this issue
is compiler-specific in any way.

I believe the Topic Police leapt at the chance to decree iostream.h Off
Topic (TM) because there's no mention of that header in the C++ Standard.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 
S

Sharad Kala

Julie said:
Feel free to doubt -- I'm going from memory on this one from about 8 years ago,
and I can barely remember my name day to day...

I can't remember where I heard it -- I just know at the time that I first heard
about extensionless headers, I thought it was a bad idea and tried to find out
the motivation. I just did a quick search on Google and couldn't turn up
anything. Perhaps someone that remembers better than I can either confirm/deny
my thought on the subject...

I can't recall anything to that effect. All I remember is that Mr. Andrew Koenig
proposed
the idea of extensionless headers to the committee.
 
J

Julie

I'll gladly stand corrected, as I've said, I'm going from 8 year old memory on
this one.

The headers were originally .h, right? and then were subsequently changed (all
prior to standardization).
 
P

P.J. Plauger

Julie said:
I'll gladly stand corrected, as I've said, I'm going from 8 year old memory on
this one.

The headers were originally .h, right? and then were subsequently changed (all
prior to standardization).

Yes, there was certainly an iostream.h. The argument during standardization
was that some people used *.h, some *.hpp, and some even other suffixes for
C++ headers. So the "compromise" was to render all of them nonconforming
by having no suffix at all.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
 

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,196
Latest member
ScottChare

Latest Threads

Top