error C2065: 'cout' : undeclared identifier

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

    Try it, it will work. I checked it in Windows XP, Visual Studio 2010 Express.

    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    
    void main( ) 
    {
       int i = 0;
       cout << "Enter a number: ";
       cin >> i;
    }
    
    0 讨论(0)
  • 2020-12-01 09:23

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


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

    I had same problem on Visual Studio C++ 2010. It's easy to fix. Above the main() function just replace the standard include lines with this below but with the pound symbol in front of the includes.

    # include "stdafx.h"
    # include <iostream>
    using  namespace std;
    
    0 讨论(0)
  • 2020-12-01 09:24

    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.

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

    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?

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

    Include the std library by inserting the following line at the top of your code:

    using namespace std;
    
    0 讨论(0)
提交回复
热议问题