Saving rdbuf()

Alex Vinokur alexvn@connect.to
Fri Aug 22 15:45:00 GMT 2003


===========================================
Windows 2000
CYGWIN_NT-5.0 1.3.22(0.78/3/2)
GNU gcc version 3.2 20020927 (prerelease)
===========================================


====== C++ code : File t.cpp : BEGIN ======

#include <iostream>
#include <fstream>
using namespace std;

int main()
{
streambuf* save_sbuf_cout;

// ---------------------------------------
// There is a design error in this program
// ------ Should be something like : -----
// ofstream log_file ("test.out");
//  save_sbuf_cout = cout.rdbuf();
//  cout.rdbuf(log_file.rdbuf());
// ---------------------------------------

  cout << "Hello-1" << endl;
  cout.rdbuf(save_sbuf_cout);
  cout << "Hello-2" << endl;

  return 0;
}

====== C++ code : File t.cpp : END ========


====== Compilation & Run : BEGIN ======

$ g++ t.cpp

$ a
Hello-1

====== Compilation & Run : END ========

No run error is generated.

Whereas MinGW (g++ 3.2) and DJGPP (g++ 3.2) do generate run error.

Why does 'CYGWIN behavior differ from MinGW and DJGPP in this case?

   =====================================
   Alex Vinokur
     mailto:alexvn@connect.to
     http://mathforum.org/library/view/10978.html
   =====================================





--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list