• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1102
  • Last Modified:

cin and cout not working

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?
0
GwynforWeb
Asked:
GwynforWeb
  • 2
  • 2
2 Solutions
 
Harisha M GCommented:
Hi GwynforWeb,
    Try
    #include <iostream.h>

    or type
    using namespace std;
    immediately before main()

    or

    use
    std::cout<<

Bye
---
Harish
0
 
GwynforWebAuthor Commented:
yep, I just noticed I had missed that :(.   Here are the points anyway:-)
0
 
Harisha M GCommented:
Those won't work in older compilers like Turbo C++ :)
0
 
AxterCommented:
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.
0
 
AxterCommented:
>>yep, I just noticed I had missed that :(.   Here are the points anyway:-)

FYI:
You didn't award the points for this question.

The question is still open.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now