
- » Professional
- » C / C++
C++ 공부를 처음 시작해서 아래 구문을 출력했다.
#include <iostream>
void main()
{
cout << "Hellow C++";
}
위의 구문을 빌드 하면 아래와 같은 에러가 발생한다.
error C2065: 'cout' : undeclared identifier
왜 그런것인가? .. 찾고 또 찾았다.. ^^
아래 내용은 문제가 발생할 수 있는 경우를 나타낸 부분의 원문을 인용한 것이다..
#include <iostream>
using namespace std;1) You should use <iostream> and not <iostream.h> if your compiler supports
it. However, that has nothing to do with your problem.
2) The problem is because the #%@& C++ committee decided that all "standard"
libraries have to be in its own namespace called "std".
3) when using a namespace you have to either use the scope resolution operator
'::' to resolve the namespace a particular function is found in...
std::cout << "start"
or use a blanket notification to the compiler by a "using" statement...
using namespace std;4) IMHO: this is the dumbest thing to ever come out of any "committee" and
anyone who voted for it should be kicked back to the Pascal/VB/Java world
where they came from.
2번의 경우가 현재 발생한 문제에 해당하며 이 문제는 아래와 같이 수정하면 된다.
#include <iostream>
using namespace std;
void main()
{
cout << "Hellow C++";
}
에러없이 출력되는 것을 확인 할 수 있을 것이다.
