views:

3245

answers:

10


!!!!solved!!! - VS2010 has a bug, works fine with eclipse Galileo


I am working on the 'driver' part of my programing assignment and i keep getting this absurd error - error C2065: 'cout' : undeclared identifier

I have even tried using the std::cout but i get another error that says: IntelliSense: namespace "std" has no member "cout" when i have declared using namespace std, included iostream + i even tried to use ostream

I know it's a standard noob question but this has stumped me and I'm a novice (meaning: I've programed before...)

#include <iostream>
using namespace std;

int main () {
    cout << "hey" << endl;
 return 0;
}

NOTE: I'm using Visual Studio 2010 - running Windows 7

NOTE: all of the .h files have "using namespace std" - and include io and o streams...

+2  A: 

before you begin this program get rid of all the code and do a simple hello world inside of main. Only include iostream and using namespace std;. Little by little add to it to find your issue.

cout << "hi" << endl; //thanks to RC for adding the l to end to make endl

JonH
i just did but nothing changed
Wallter
Ok so do what everyone else said. Get rid of all your code. just keep the using namespace and the header iostream. then put this in:int main(void) { std::cout << "Hello, World!" << std::endl; return 0; } tell us if that works.
JonH
If it won't compile a file with just `#include <iostream> int main() { std::cout << "ok"; }`, then something is badly broken in your C++ implementation. What compiler are you using?
Pavel Minaev
Also it's main not Main. Case is important in C++. I suggest you google C++ hello world.
JonH
Get rid of that semi colon after the function bob. It comes before main so you do not need it.
JonH
Wallter
I don't think VS 2010 Beta 2 is usable for C++ yet. There's some serious problems with the headers. I can't compile anything I've got on it.
David Thornley
@David: that would be extremely strange, as I use VS2010 beta 2 quite a lot, specifically for C++, without any problems. If you have some serious troubles, please report it as a bug at MS Connect! (https://connect.microsoft.com/VisualStudio/feedback/)
Pavel Minaev
@Wallter: are you compiling this from VS? or from command line using `cl.exe`?
Pavel Minaev
@Pavel Minaev: using the built in CTRL-F5 build all feature
Wallter
+1  A: 

The code below compiles and runs properly for me using gcc. Try copy/pasting this and see if it works.

#include <iostream>
using namespace std;

int bob (int a) { cout << "hey" << endl; return 0; };

int main () {
    int a = 1;
    bob(a);
    return 0;
}
Glen
Wallter
Does std::cout work? I don't know much about Visual Studio, are you sure you've set the project up correctly as a C++ project? If you open the file iostream does it contain a cout declaration?
Glen
Given that VS2010 is still beta it might be a bug (which beta version are you using?). But I find it hard to believe that something so basic doesn't work correctly.
Glen
that's why it's blowing my mind :)
Wallter
+2  A: 

If the only file you include is iostream and it still says undefined, then maybe iostream doesn't contain what it's supposed to. Is it possible that you have an empty file coincidentally named "iostream" in your project?

Bob Lied
+1  A: 

Are you sure it's compiling as C++? Check your file name (it should end in .cpp). Check your project settings.

There's simply nothing wrong with your program, and cout is in namespace std. Your installation of VS 2010 Beta 2 is defective, and I don't think it's just your installation.

I don't think VS 2010 is ready for C++ yet. The standard "Hello, World" program didn't work on Beta 1. I just tried creating a test Win32 console application, and the generated test.cpp file didn't have a main() function.

I've got a really, really bad feeling about VS 2010.

David Thornley
Given that VS2010 is written using itself (and compiled using VC10 compiler, and the code uses new C++0x features such as lambdas, etc), I can assure you that it's quite ready for C++. If you have problems with "Hello, world" applications, then it sounds like a broken install (which is likely a bug), or some post-install bug. Either way it's not normal, and it's definitely not a normal experience in either beta 1 or beta 2, so please report it as a bug on Connect.
Pavel Minaev
@Pavel: Thanks; as you can tell, I haven't been getting it to work. Sometime after this current crisis I'll try to get some bug reports in.
David Thornley
+1  A: 

I have VS2010, Beta 1 and Beta 2 (one on my work machine and one at home), and I've used std plenty without issues. Try typing:

std::

And see if Intellisense gives you anything. If it gives you the usual stuff (abort, abs, acos, etc.), except for cout, well then, that is quite a puzzler. Definitely look into your C++ headers in that case.

Beyond that, I would just add to make sure you're running a regular, empty project (not CLR, where Intellisense is crippled), and that you've actually attempted to build the project at least once. As I mentioned in a comment, VS2010 parses files once you've added an include; it could be that something stuck the parser and it didn't "find" cout right away. (In which case, try restarting VS maybe?)

Dan Tao
+1  A: 

I've seen similar things happen when I was using the .c file extension with C++ code. Other than that, I'd have to agree with everyone about a buggy installation. Does it work if you try to compile the project with an earlier release of VS? Try VC++ Express 2008. Its free on msdn.

Good Luck

-C

goatlinks
Yeah it was the VS2010 - i'v installed eclipse Galileo and the program ran just fine!!!
Wallter
+1  A: 

i've got the same problem and i as well have programmed before and it is honestly driving me up the wall.

#include <iostream>
using namespace std;
//#include "stdafx.h"
#include <conio.h>

int main ()
{
 cout << "Hello World!";
  return 0;
}

I've tried everything that i've found on various forums but nothing new is happening.. Im using Windows XP with Microsoft Visual Studio 2008..

Amelia
yeah! i'm not alone/insane
Wallter
It's the compiler...
Wallter
A: 


It was the compiler - I'm now using Eclipse Galileo and the program works like a wonder


Wallter
It's not the compiler.
GMan
It was the compiler, at the time Visual studio was in the Beta stage, this was one of the bugs that they would later debug out of the compiler. I am now using the official release of the the Visual Studio 2010 compiler and all is working. There is no question that the compiler was the problem. (as stated below by Amelia - I was not alone in this problem)
Wallter
A: 

is normally stored in the C:\Program Files\Microsoft Visual Studio 8\VC\include folder. First check if it is still there. Then choose Tools + Options, Projects and Solutions, VC++ Directories, choose "Include files" in the "Show Directories for" combobox and double-check that $(VCInstallDir)include is on top of the list.

Manohar