error C2065: 'cout' : undeclared identifier

前端 未结 25 2133
误落风尘
误落风尘 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:26

    I came here because I had the same problem, but when I did #include "stdafx.h" it said it did not find that file.
    What did the trick for me was: #include <algorithm>.
    I use Microsoft Visual Studio 2008.
    These are the things that you can use then, incl. 'count': Link

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

    I have seen that if you use

    #include <iostream.h>
    

    then you will get the problem.

    If you use

    #include <iostream>  
    

    (notice - without the .h)

    then you will not get the problem you mentioned.

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

    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.

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

    I had the same issue when starting a ms c++ 2010 project from scratch - I removed all of the header files generated by ms and but used:

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    int main() {
       cout << "hey" << endl;
       return 0;
    }
    

    I had to include stdafx.h as it caused an error not having it in.

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

    I ran across this error after just having installed vs 2010 and just trying to get a nearly identical program to work.

    I've done vanilla C coding on unix-style boxes before, decided I'd play with this a bit myself.

    The first program I tried was:

    #include "stdafx.h"
    
    
    int _tmain(int argc, _TCHAR* argv[])
    {
        cout << "Hello World!";
        return 0;
    }
    

    The big thing to notice here... if you've EVER done any C coding,

    int _tmain(int argc, _TCHAR* argv[])
    

    Looks weird. it should be:

    int main( int argc, char ** argv )
    

    In my case I just changed the program to:

    #include <iostream>
    using namespace std;
    
    int main()
    {
         cout << "Hello world from  VS 2010!\n";
         return 0;
    }
    

    And it worked fine.

    Note: Use CTRL + F5 so that the console window sticks around so you can see the results.

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

    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.

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