This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: cerr not defined
- From: Oliver Kullmann <O dot Kullmann at Swansea dot ac dot uk>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 20 Jan 2003 20:24:31 +0000
- Subject: Re: cerr not defined
- References: <3E2C1136.19539.200B702F@localhost>
>
> 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 17.4.1.2 of the
> C++ standard
> and all of the standard C library headers (according to the same
> standard).
>
> 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[1]);
> if(!from) error ("cannot open input file", argv[1]);
>
> std::ofstream to( argv[2]);
> if( !to ) error( "cannot open output file", argv[2]);
>
> 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?
>
> Thanks,
> Shane
>
> shane@shaneroberts.com
>
Hi,
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>.
Oliver