[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: compiling with g++ 3.3



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;

// 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++

-- 
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

Attachment: pgput2oB9VXwp.pgp
Description: PGP signature


Reply to: