Re: compiling with g++ 3.3
On Sun, 15 Jun 2003 01:59:12 -0500
Nathan Poznick <poznick@conwaycorp.net> wrote:
> Thus spake Shawn Lamson:
> > I refer to page:
> > http://gcc.gnu.org/onlinedocs/libstdc++/17_intro/headers_cc.txt
> > which lists iostream as a standard library header. So why throw the
> > message from "backward/backward_warning.h" at me?
> > In addition, if I alter the #include to be
> > #include </usr/include/g++-3/iostream>
> > then I still get the "backward" warning, but note that I don't have
> > to put ".h" after the "iostream".
>
> That's very bad practice. You should never put an absolute path to
> a header file in an include statement...Especially for a standard
> header.
>
> > The goal here is to have a program reading:
> > #include <iostream>
> > int main(){
> > cout<<"Hello, world!"<<endl;
> > return 0;
> > }
>
> If that's your goal, then what's the problem?
>
> kraken@tao:~$ cat test.cpp
> //test.cpp
> #include <iostream>
> using namespace std;
> int main()
> {
> cout<<"Hello, world!"<<endl;
> return 0;
> }
>
> kraken@tao:~$ g++-3.3 -o test.out test.cpp
> kraken@tao:~$ ./test.out
> Hello, world!
>
> Note the using namespace std; line. Once you simply #include
> <iostream>, the only thing keeping it from compiling is the fact that
> cout and endl are now in the std:: namespace. Thus, you can do one of
> the three following things:
>
> // assumes std:: in front of things
> using namespace std;
Yes, that did the trick, thank you for your help, Nathan. See below for
the directories issue.
>
> // import into your namespace only the things you want
> using std::cout;
> using std::endl;
>
> // always qualify the things you're using which exist
> // in the std namespace
> std::cout << "foobar" << std::endl;
>
> > P.S. - which libraries are best to use; /usr/include/g++-3/ or
> > /usr/include/c++/3.3/ ?
>
> Neither should be used directly. The compiler will automatically
> search those paths, unless you use -nostdinc or -nostdinc++
It actually doesn't look like it does search the /usr/include/g++-3/
directory.
ignoring nonexistent directory "/usr/i386-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/3.3
/usr/include/c++/3.3/i386-linux
/usr/include/c++/3.3/backward
/usr/local/include
/usr/lib/gcc-lib/i386-linux/3.3/include
/usr/include
End of search list.
-------------------------------------------------------
should it be?
Shawn
> --
> Nathan Poznick <poznick@conwaycorp.net>
>
> A duty dodged is like a debt unpaid; it is only deferred, and we must
> come back and settle the account at last. - Joseph F. Newton
>
>
Shawn Lamson
shawn.lamson@verizon.net
Debian GNU/Linux 3.0
Reply to: