Archived

This topic is now archived and is closed to further replies.

Why won't cout work?

This topic is 4942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I started a new console project in VC++ 7.0. For some reason, it doesn''t recogize cout or endl as valid commands. I tried adding #include, but all sorts of things crashed. By default, when it starts up, it has #include "stdafx.h", and stdafx.h has #include in it. What do I need to do to use iostream? Thanks. -Nick

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by uber_n00b
try #include <iostream.h>


No no no no NO!!! This is not standard C++. The standard headers do NOT have .h in their name!


Share this post


Link to post
Share on other sites
Would you mind explaining that again? I use that exact statement in all my console apps because I personally have VC++ 7.0. I realize standard headers don't have .h, but what do you mean this isn't 'standard' C++?

Edit: I misread because of your ambiguous "this", which I interpreted to mean the situation described by the poster but in fact you meant my #include directive. What is so wrong with it if he's using VC++? sure you could just type using std::cout and using std::endl at the top, but why bother if VC++ makes it easier..?

[edited by - uber_n00b on May 31, 2004 2:21:00 PM]

Share this post


Link to post
Share on other sites
In ANSI-C++ the way to include header files from the standard library has changed.

The standard specifies the following modification from the C way of including standard header files:
Header file names no longer maintain the .h extension typical of the C language and of pre-standard C++ compilers, as in the case of stdio.h, stdlib.h, iostream.h, etc. This extension h simply disappears and files previously known as iostream.h become iostream (without .h).
Header files that come from the C language now have to be preceded by a c character in order to distinguish them from the new C++ exclusive header files that have the same name. For example stdio.h becomes cstdio .
All classes and functions defined in standard libraries are under the std namespace instead of being global. This not applies to C macros that remain as C macros.



[edited by - Tha_HoodRat on May 31, 2004 2:26:02 PM]

Share this post


Link to post
Share on other sites