What does " not declared in this scope" error in C++ mean. How can I solve it? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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?

21st Dec 2016, 2:56 PM
Shobhit Singh
Shobhit Singh - avatar
2 Answers
+ 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.
21st Dec 2016, 3:25 PM
Hatsy Rei
Hatsy Rei - avatar
+ 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.
21st Dec 2016, 4:22 PM
Navjot Singh Cheema