stdcxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Misha Aizatulin <ava...@hot.ee>
Subject Documentation example doesn't compile with gcc
Date Sat, 15 Nov 2008 06:01:26 GMT
hi all,

  at the very end of http://stdcxx.apache.org/doc/stdlibug/34-2.html
there is an example of using a reference to create a "copy" of cout.
However this example doesn't initialize the defined reference at once
(which is required in C++) and for this reason doesn't compile with my
gcc 4.2.1.

  For convenience here is the example:

int main(int argc, char *argv[])
{
  std::ostream& fr;
  if (argc > 1)
    fr = *(new std::ofstream(argv[1]));
  else
    fr = std::cout;

  fr << "Hello world!" << std::endl;

  if (&fr!=&std::cout)
    delete(&fr);
}

Cheers,
  Misha

Mime
View raw message