Why won't cout work?

Started by
8 comments, last by nickwinters 19 years, 10 months ago
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
Advertisement
#include <iostream>int main() {    std::cout << "HELLO" << std::endl;    return 0;}


[edited by - snk_kid on May 31, 2004 11:21:08 AM]
Is there a way to not have to put the std in front of it? I''m lazy. :-D
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.
using std::cout;
using std::cin;

out that right after your includes
try #include <iostream.h>
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
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!


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]
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.
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]
I was influenced by the Ghetto you ruined.
Thanks o.O
My fellow Americans I have just signed legislation that outlaws Russia forever. Bombing will commence in five minutes.

This topic is closed to new replies.

Advertisement