Re: C++ compile error



David Miao wrote:
On 12/16/05, Nathan Vidican <nvidican@xxxxxxxxx> wrote:
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@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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



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@xxxxxxxxx
Windsor Match Plate & Tool Ltd.
http://www.wmptl.com/


Nathan,

I'm learning c++ programming language by using "The complete c++
training course - second edition" (Harvey Deitel & Paul Deitel), hello
world is the first program in this book.  I'm totally puzzled by this
complex language when I compile my first program. Is this book out of
date?

No, Deitel and Deitel isn't too bad. If you are new to programming in general, I highly recommned "C++ : A Dialog", by Steve Heller. He gradually takes someone along to learn programming with C++. In fact, the full text is available on his web site:

http://www.steveheller.com/cppad/Output/dialogTOC.html

--
Jonathan Arnold     (mailto:jdarnold@xxxxxxxxxxxx)
Daemon Dancing in the Dark, a FreeBSD weblog:
   http://freebsd.amazingdev.com/blog/

UNIX is user-friendly. It's just a bit picky about who its friends are.

_______________________________________________
freebsd-questions@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: C++ compile error
    ... hello.C: In function `int main': hello.C:5: error: `cout' undeclared hello.C:5: error: (Each undeclared identifier is reported only once for each function it appears in.) ... cout is part of the 'std' namespace, ...
    (freebsd-questions)
  • Re: help with hello world
    ... yggdrasil> cat test.cpp ... {cout << "Hello World"; ... test.cpp: In function `int main': ... test.cpp:4: error: (Each undeclared identifier is reported only once for each ...
    (freebsd-questions)
  • Re: C++ standard libraries for gcc 3.3.5
    ... hello.cpp: In function `int main': ... hello.cpp:5: error: `cout' undeclared ... hello.cpp:5: error: (Each undeclared identifier is reported only once ...
    (comp.os.os2.programmer.misc)
  • Re: C++ standard libraries for gcc 3.3.5
    ... hello.cpp: In function `int main': ... hello.cpp:5: error: `cout' undeclared ... hello.cpp:5: error: (Each undeclared identifier is reported only once ... But it is found very deeply in the file tree. ...
    (comp.os.os2.programmer.misc)
  • Re: Could use some help...:)
    ... cout << endl ... int B::operator (unsigned row, unsigned column) ...
    (comp.lang.cpp)