cerr not defined
Mon Jan 20 20:26:00 GMT 2003
> I am running gcc version 3.2 20020927 under Cygwin
> 1.3.18(0.69/3/2) 2002-12-25
> on Windows XP Professional.
> I am trying to compile C++ examples from the book Computer
> Graphics using Open GL by F. S. Hill, Jr. Some of the examples
> work but now I am having trouble with the streams library.
> I have included all the 32 headers found in section 18.104.22.168 of the
> C++ standard
> and all of the standard C library headers (according to the same
> But "ios" continues to be "undeclared".
> I have also tried compiling the standard example of stream io from
> Strousstrup's "The C++ Programming Language - Third Edition"
> page 637 section 21.5.1 File Streams. But I get:
> $ g++ testiostream.cpp
> testiostream.cpp: In function `void error(const char*, const char*)':
> testiostream.cpp:8: `cerr' undeclared
> (first use this function)
> testiostream.cpp:8: (Each undeclared identifier is reported only
> once for each
> function it appears in.)
> The code is:
> _____________________Start of Code___________________
> #include <fstream>
> #include <cstdlib>
> void error(const char* P, const char* P2 = "" )
> cerr << P << ' ' << P2 << '\n' ;
> std::exit(1) ;
> int main(int argc, char* argv)
> if(argc != 3) error( "wrong number of arguments");
> std::ifstream from( argv);
> if(!from) error ("cannot open input file", argv);
> std::ofstream to( argv);
> if( !to ) error( "cannot open output file", argv);
> char ch;
> while ( from.get(ch) ) to.put( ch ) ;
> if( !from.eof() || !to ) error( "something strange happened");
> ________________ End of Code_________________
> Anybody know what gcc options or includes or what I need to add
> or change to make this work?
strange, why do you qualify most names with "std::" but not "cerr" --- it
needs the namespace qualifier "std::" as well!
And it is new to me that cerr comes with <fstream>; I think it is only
included via <iostream>.
More information about the Gcc-help