There are three possible reasons of this error and this is the same kind of error cout was not declared in this scope.
- You are missing the header file <iostram> in you program
- You are not using std:: before endl in your main program ( if you did not declare it before main program ).
- You are missing using namespace std before main program.
Here is an example in which using namespace std is missing and also did not use std:: before endl statement so we have error ” endl was not declared in this scopes “.
How to solve ” cout was not declared in this scope error ” ?
First put #include <iostram> if you are missing this at the very top of your program then try these three methods.
You can solve this error by putting std:: before endl and use std:: every time when you use endl statement in your program.
Declare ” using std::endl ” before main function so you will not face ” endl was not declare in this scope error “.
You can put using namespace std before main program so that you don’t have to use std:: before every endl statement in your program. See picture below after solving this error with using namespace std.
Use “ using namespace std “ before main program so that you will not have to face this “ cout was not declare in this scope “ error and you will not have to use std:: before using cout and endl statement.