C++ compile error
Nathan Vidican
nvidican at wmptl.com
Fri Dec 16 07:34:08 PST 2005
David Miao wrote:
> Dear list,
>
> I try to compile a hello world C++ program in FreeBSD 6.0, but get an
> error as below:
>
> [dm at ORION ~/cpp]% CC -o hello hello.C
> hello.C: In function `int main()':
> hello.C:5: error: `cout' undeclared (first use this function)
> hello.C:5: error: (Each undeclared identifier is reported only once
> for each function it appears in.)
> hello.C:5: error: `endl' undeclared (first use this function)
>
> I noticed that "iostream" file is located in
> "/usr/include/c++/3.4/iostream", I guess my CC compiler cannot find
> this head file. Is it true? And how can I fix this problem? Your
> advice is appreciated. Thanks in advance.
>
> ==quote of hello world code==
> #include <iostream>
>
> int main()
> {
> cout << "Hello World!" << endl;
>
> return 0;
> }
> == end of quote==
>
> Regards,
> David
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"
>
>
>
Also, noticed your code is flawed, you never used a namespace, nor explicitly
stated one. cout is part of the 'std' namespace, so either ' using namespace
std;' for global/local use of namespace, OR do 'std::cout <<' instead. Try the
hello.cpp I sent you in the last email, that one should work for ya :)
--
Nathan Vidican
nvidican at wmptl.com
Windsor Match Plate & Tool Ltd.
http://www.wmptl.com/
More information about the freebsd-questions
mailing list