I am trying to compile the simple program below. But, it's not compiling & gives error:
error C2065: 'cout' : undeclared identifier
I want to ask you that why this program doesn't work though I've included iostream
header file in it?
#include <iostream>
void function(int) { cout << “function(int) called” << endl; }
void function(unsigned int) { cout << “function(unsigned int) called” << endl; }
int main()
{
function(-2);
function(4);
return 0;
}
Thanks in advance.
std::cout
instead ofcout
only. Appendstd::
before everything you use fromnamespace std
. – Contraindicateusing namespace std;
somewhere below your#include <iostream>
. It will inform the compiler to look forcout
in std namespace, thus allowing yourcout
to work. Although this is considered a bad practice whatsoever. – Merisusing namespace std;
. That is guaranteed to bite you one day. If you don't want to typestd::cout
, useusing std::cout
, but limit it to a small scope, and don't use it in headers. – Padraigusing namespace std
issue here: #1453221 – Padraig