error C2065: 'cout' : undeclared identifier

前端 未结 25 2131
误落风尘
误落风尘 2020-12-01 08:40

I am working on the \'driver\' part of my programing assignment and i keep getting this absurd error:

error C2065: \'cout\' : undeclared identifier

相关标签:
25条回答
  • 2020-12-01 09:13

    If you started a project requiring the #include "stdafx.h" line, put it first.

    0 讨论(0)
  • 2020-12-01 09:15

    Just use printf!

    Include stdio.h in your stdafx.h header file for printf.

    0 讨论(0)
  • 2020-12-01 09:16

    When you created your project, you did not set 'use precompiled headers' correctly. Change it in properties->C/C++->precompiled headers.

    0 讨论(0)
  • 2020-12-01 09:21

    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?)

    0 讨论(0)
  • 2020-12-01 09:21

    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;
    
    0 讨论(0)
  • 2020-12-01 09:22

    Such a silly solution in my case:

    // Example a
    #include <iostream>    
    #include "stdafx.h"
    

    The above was odered as per example a, when I changed it to resemble example b below...

    // Example b
    #include "stdafx.h"
    #include <iostream>  
    

    My code compiled like a charm. Try it, guaranteed to work.

    0 讨论(0)
提交回复
热议问题