Home c++ Error: undeclared Identifier

Error: undeclared Identifier




Hello! I write the first program on C++ and I do not understand why the error is displayed:

Error C2065: ‘Cout’: undeclared Identifier
Error C2065: ‘ENDL’: undeclared Identifier

Here is the code:

# include & lt; iostream & gt;
  COUT & LT; & LT; "Hello World" & lt; & lt; Endl; // Error here

Error in line №3.
Tell me, please, what could be the problem?

Answer 1, Authority 100%

You need to define the namespace STD . All identifiers of the standard C++ library are defined in the namespace with the same name. Namespace determines the scope of the visibility of identifiers. You can determine directly when the “Hello World” is displayed (this entry is called directly refinement of the identifier):

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

There is also a different way: you can write before the main () function :

using namespace STD;

This entry is used most often (for simplicity, in short listings). It means that after its execution all the identifiers of the STD are available as if they were declared globally. However, it is not necessary to abuse such a record, because in complex programs it can lead to periodic conflicts of names, to unpredictable consequences due to overload rules.

Another use of a certain namespace. The example shows how you can get a local ability to skip the prefix STD :: for Cout and Endl :

using std :: cout;
Using STD :: ENDL;
Previous articleCallback Call
Next articleWhat is token?

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