У меня есть программа C++:
test.cpp
Я получаю сообщение об ошибке:
‘cout’ не был объявлен в этой области
Поместите следующий код перед int main() :
И вы сможете использовать cout .
Теперь уделите минутку и прочитайте, что такое cout и что здесь происходит:
Кроме того, хотя это быстро и работает, это не совсем хороший совет, просто добавить using namespace std; вверху кода. Для подробного правильного подхода, пожалуйста, прочитайте ответы на этот связанный вопрос SO.
I have a C++ program:
test.cpp
I get the error:
‘cout’ was not declared in this scope

closed as too localized by casperOne Mar 4 ’13 at 12:42
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldw >If this question can be reworded to fit the rules in the help center, please edit the question.
2 Answers 2
Put the following code before int main() :
And you will be able to use cout .
Now take a moment and read up on what cout is and what is going on here:
Further, while its quick to do and it works, this is not exactly a good advice to simply add using namespace std; at the top of your code. For detailed correct approach, please read the answers to this related SO question.
just a simple program but can anyone point out why this error is occuring, (i am using dev C++ version 5.11)
the error is coming like this:
2 Answers 2
At least you have to include
The name cout is declared in the namespace std . So either use the using directive as shown above or use a qualified name (that is better) like
An alternative approach is to use a using declaration. For example
And remove this directive
Also place semicolons
Pay attention to that the function main shall be declared like
Please, stop using the old Borland C++ et al.
Use a modern standards compliant C++ compiler (g++, clang, Microsoft Visual Studio) instead.
Do not use conio.h, it is a very old compiler specific library, not a standard one.
Do not use stdio.h it is not a bad library, but it declares several C functions, not C++ ones.
Declare your main function as
not void main() , because standard C++ needs the main function to return an int (0 for success).
Instead of using cout , use std::cout , because it is an object representing the standard output defined inside the std namespace.