1

I don't know if I am just using the wrong keywords.. but I can't find an answer on google. Not can I wrap my feeble mind around my error.

This is a simple demonstration of the error:

#include <iostream>

//std::cout << "hello";

int main()
{
    std::cout << "hello";
    return 0;
}

Upon compiling/running this I receive this error:

main.cpp:3:6: error: 'cout' in namespace 'std' does not name a type

However, if I remove the first cout line, and just allow the program to execute the one inside of the main function, it works just fine.

Anyone got any ideas?

Jeffrey
  • 11,063
  • 1
  • 21
  • 42
Sam Tubb
  • 945
  • 3
  • 19
  • 40

1 Answers1

5

You cannot run code outside functions in C++. The compiler only expect variable declarations outside functions and, thus, expects std::cout to be a type, which it is not.

Jeffrey
  • 11,063
  • 1
  • 21
  • 42