Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ cout gives undeclared identifier

Tags:

c++

cout

So, I have this question. Why does cout throws

error C2065: 'cout' : undeclared identifier

I am using Visual Studio 2012 as an IDE and I am writing a school project. I have everything done except an example file. So I am trying to write something on the screen like this:

#include "iostream"
#include "stdafx.h"
using namespace std;

int main()
{
    cout<<"example";

    return 0;
}

So the problem is with cout... printf works fine, but I want to use cout.

EDIT: I've changed "" to <> but it is not helping. Also I am using this code only for example... This is not the whole project.

like image 720
Dekay Avatar asked May 31 '13 13:05

Dekay


Video Answer


1 Answers

stdafx.h shall be the first include directive in your source file.

Switch files and convert the second include to <>, as other suggested.

#include "stdafx.h"
#include <iostream>

See this post for more information.

like image 90
Matthieu Rouget Avatar answered Sep 20 '22 21:09

Matthieu Rouget