error C2065: 'cout' : undeclared identifier

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

    In Visual Studio you must #include "stdafx.h" and be the first include of the cpp file. For instance:

    These will not work.

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

    This will do.

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

    Here is a great answer on what the stdafx.h header does.

提交回复
热议问题