[FIXED] Code::Blocks error: 'cout' was not declared in this scope
![]() |
Code::Blocks error: 'cout' was not declared in this scope |
Luckily, there are two simple ways to fix this error:
Method 1
Use this statement before your main function:using namespace std;So that your code looks something like:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
Method 2
Instead of using cout , try using std::cout so that the code looks something like:#include <iostream>
int main()
{
std::cout << "Hello world!";
return 0;
}
Either way, you're telling the compiler to search for cout function in the standard directory (not current directory).
Note: If you're using Method 2, then you'll need to add that extra std:: to all your <iostream> functions, which is quite a hassle, tbh. I recommend using Method 1.
That's it! Now try to compile and run the program (assuming the program is written correctly), it should work.