error C2065: 'cout' : undeclared identifier

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

提交回复
热议问题