This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: STL with gcc3


Ji Li writes:
> 	I am experiencing some problem with STL when compile with gcc3. I
> have a little piece of c++ code like this:
> 
> 	#include <iostream>
> 	#include <string>
> 
> 	int main(){
> 	string aa = "Hello World !";
> 
> 	cerr << aa << endl;
> 	}

As has been pointed out, this won't compile with almost any current
C++ compiler from any vendor.

> 	If I compile it with gcc-2.96, there is no problem. However, when
> I compile it with gcc-3.0.4, the compiler does not recognize neither
> 'string' nor 'cerr'. But if I add 'using namespace std;', gcc-3.0.4 works
> fine with it.

And so will gcc-2.95.x and Red Hat's gcc-2.96.  As a transition aid, those
compilers had a flag called honor_std which is false by default.  When
honor_std is false, specifying std::cout will look for cout instead, and
using directives that bring part or all of the std namespace into the
global namespace are ignored.

The intent was to get programmers started in writing their C++ code the
right way.  Unfortunately, there are too many Unix/Linux/BSD hackers who
never used a C++ compiler other than GNU and kept blithely kept coding the
old way.

> 	I believe there must be a way to make gcc-3.0.4 backward
> compatable but just could find it. Would you please point the way for me?

Make your code backward compatible instead.  If you need for your code to
build with older GNU compilers as well as current compilers (from GNU
and/or others), put in the line "using namespace std;" or say std::string,
std::cerr and std::endl.  The resulting code will work with both old and
new compilers.

The std namespace has been standard for four years now and in the draft
standard for a few years before that.  Sorry, time's up.  Time to write
real C++ code.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]