#### Archived

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

# Why won't cout work?

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

## 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 on other sites
#include <iostream>int main() {    std::cout << "HELLO" << std::endl;    return 0;}

[edited by - snk_kid on May 31, 2004 11:21:08 AM]

##### Share on other sites
Is there a way to not have to put the std in front of it? I''m lazy. :-D

##### Share on other sites
Put ''using namespace std;'' at the top of the program. Though that is considered bad practice. Things are put in a namespace for a reason.

##### Share on other sites
using std::cout;
using std::cin;

out that right after your includes

##### Share on other sites
try #include <iostream.h>

##### Share on other sites
quote:
Original post by uber_n00b
try #include &lt;iostream.h>

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

##### 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 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]

Thanks o.O

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633697
• Total Posts
3013407
×