Home c++ Error: cout: undeclared identifier

Error: cout: undeclared identifier [duplicate]

Author

Date

Category

I just started to figure out the pros. And then he stuck into some kind of incomprehensible jamb.

# include & lt; iostream & gt;
#include "stdafx.h"
using namespace std;
int main ()
{
  cout & lt; & lt; "Hello World" & lt; & lt; endl;
}

Everything seems to be correct … But when compiling an error:

cout: undeclared identifier

I read similar topics here. They write that the namespace must be declared, it is. Everything seems to be all right. I am using VS 2017 to write code. Please explain what is wrong.


Answer 1, authority 100%

This is it

# include & lt; iostream & gt;

you probably added yourself before

# include "stdafx.h"

Swap them. stdafx.h is such a really tricky auxiliary header file (which I honestly wouldn’t use at all 🙂 – but you’ve already made a project using a precompiled header …) Let’s go first …

# include "stdafx.h"
#include & lt; iostream & gt;
using namespace std;
int main ()
{
  cout & lt; & lt; "Hello World" & lt; & lt; endl;
}

Answer 2

try this

# include & lt; iostream & gt;
using namespace std;
int main ()
{
  cout & lt; & lt; "Hello World";
  return 0;
}

Answer 3

std :: cout & lt; & lt; "Hello World";

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions