cin and cout not working

Posted on 2005-05-16
Last Modified: 2008-02-01
I am using and old version of Visual C++ on one of our machines and am having trouble with cout and cin. If I run the following console app

#include "stdafx.h"
#include <iostream>

int main(){
 cout <<"hello world";
 return 0;

I get the errors

error C2065: 'cout' : undeclared identifier
error C2297: '<<' : illegal, right operand has type 'char [12]'
error C2059: syntax error : ';'

I am guessing that <iostream> is some how not getting included. If I use printf("hello world") all works fiine. Any ideas?
Question by:GwynforWeb
    LVL 37

    Accepted Solution

    Hi GwynforWeb,
        #include <iostream.h>

        or type
        using namespace std;
        immediately before main()



    LVL 31

    Author Comment

    yep, I just noticed I had missed that :(.   Here are the points anyway:-)
    LVL 37

    Expert Comment

    by:Harisha M G
    Those won't work in older compilers like Turbo C++ :)
    LVL 30

    Assisted Solution

    You should not use <iostream.h>
    That's not part of the C++ standard, and therefore not portable, and will not compile on compliant compilers like VC++ 7.1

    Instead  you should use the <iostream> and if desired, add using namespace std;

    You could alternatively fully qualify your STL objects with std:: prefix.
    LVL 30

    Expert Comment

    >>yep, I just noticed I had missed that :(.   Here are the points anyway:-)

    You didn't award the points for this question.

    The question is still open.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
    What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
    The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now