+ 2
What does " not declared in this scope" error in C++ mean. How can I solve it?
The most frequent error which I get in coding on solo learn platform is " cout not declared in this scope" or " cin not declared in this scope". Why does it happen and how can I solve it?
2 Respostas
+ 3
You have to include the <iostream> header in your source code, since the header provides the input and output streams, i.e. contains cin and cout functionalities. Hope this helps.
Else, you may have to provide your code for further inspection.
+ 1
cin and cout are defined in the scope of namespace std.
Why does it happen?
The compiler is not able to find a definition for cin and cout.
How to resolve it?
After #include <iostream>, you can use std::cin or std::cout to avoid this error. By using 'std::' before cin and cout you are specifying the scope of cin and cout.
or
use the following:
#include <iostream>
using namespace std;
If you use the above code you don't need to use 'std:: namespace scope resolution for each cin and cout use.