‘cout’ was not declared in this scope

From Cppsyntax

Jump to: navigation, search

You can get the error

 ‘cout’ was not declared in this scope

if you forget to include iostream or to use the std namespace.

WRONG

 #include <iostream>  // no using namespace std;
 int main(void) 
 {
   cout << "A";
   return 0;
 }


ALSO WRONG

 using namespace std;   // no #include iostream
 int main(void) 
 {
   cout << "A";
   return 0;
 }

RIGHT

 #include <iostream>   // one of two
 using namespace std;    // two of two, yay!
 int main(void) 
 {
   cout << "A";
   return 0;
 }