From: "Alex Vinokur" Newsgroups: comp.os.msdos.djgpp,gnu.g++.help Subject: ofstream and rdbuf() Date: Thu, 19 Dec 2002 07:45:29 +0200 Lines: 147 Message-ID: References: NNTP-Posting-Host: pop03-2-ras2-p229.barak.net.il (212.150.98.229) X-Trace: fu-berlin.de 1040276754 2065729 212.150.98.229 (16 [79865]) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com =============== Windows 2000 DJGPP 2.03 GNU gcc/gpp 3.1 =============== I have got compilation errors related to ofstream and rdbuf(). Is there any way to do what I want to ? Thanks in advance. ========= C++ code : BEGIN ========= // File t1.cpp #include #include #include using namespace std; int main () { streambuf *psbuf_file1; streambuf *psbuf_file2; streambuf *psbuf_cout; streambuf *psbuf_cerr; ofstream file1; ofstream file2; file1.open ("f1.txt"); assert (file1); file2.open ("f2.txt"); assert (file2); psbuf_cout = cout.rdbuf(); assert (psbuf_cout); psbuf_cerr = cerr.rdbuf(); assert (psbuf_cerr); psbuf_file1 = file1.rdbuf(); assert (psbuf_file1); psbuf_file2 = file2.rdbuf(); assert (psbuf_file2); cout << "AAA to cout" << endl; cerr << "AAA to cerr" << endl; file1 << "AAA to file1" << endl; file2 << "AAA to file2" << endl; cout.rdbuf(psbuf_file1); cerr.rdbuf(psbuf_file2); cout << "BBB to cout" << endl; cerr << "BBB to cerr" << endl; file1 << "BBB to file1" << endl; file2 << "BBB to file2" << endl; cout.rdbuf(psbuf_cout); cerr.rdbuf(psbuf_cerr); cout << "CCC to cout" << endl; cerr << "CCC to cerr" << endl; file1 << "CCC to file1" << endl; file2 << "CCC to file2" << endl; file1.rdbuf(psbuf_cout); // Line#61 file2.rdbuf(psbuf_cerr); // Line#62 cout << "DDD to cout" << endl; cerr << "DDD to cerr" << endl; file1 << "DDD to file1" << endl; file2 << "DDD to file2" << endl; file1.rdbuf(psbuf_file1); // Line#71 file2.rdbuf(psbuf_file2); // Line#72 cout << "EEE to cout" << endl; cerr << "EEE to cerr" << endl; file1 << "EEE to file1" << endl; file2 << "EEE to file2" << endl; file1.close(); assert (file1); file2.close(); assert (file2); return 0; } ========= C++ code : END =========== ========= Compilation : BEGIN ========= % gpp t1.cpp t1.cpp: In function `int main()': t1.cpp:61: no matching function for call to `std::basic_ofstream >::rdbuf(std::streambuf*&)' c:/djgpp/lang/cxx-v31/fstream:424: candidates are: std::basic_filebuf<_CharT, _Traits>* std::basic_ofstream<_CharT, _Traits>::rdbuf() const [with _CharT = char, _Traits = std::char_traits] t1.cpp:62: no matching function for call to `std::basic_ofstream >::rdbuf(std::streambuf*&)' c:/djgpp/lang/cxx-v31/fstream:424: candidates are: std::basic_filebuf<_CharT, _Traits>* std::basic_ofstream<_CharT, _Traits>::rdbuf() const [with _CharT = char, _Traits = std::char_traits] t1.cpp:71: no matching function for call to `std::basic_ofstream >::rdbuf(std::streambuf*&)' c:/djgpp/lang/cxx-v31/fstream:424: candidates are: std::basic_filebuf<_CharT, _Traits>* std::basic_ofstream<_CharT, _Traits>::rdbuf() const [with _CharT = char, _Traits = std::char_traits] t1.cpp:72: no matching function for call to `std::basic_ofstream >::rdbuf(std::streambuf*&)' c:/djgpp/lang/cxx-v31/fstream:424: candidates are: std::basic_filebuf<_CharT, _Traits>* std::basic_ofstream<_CharT, _Traits>::rdbuf() const [with _CharT = char, _Traits = std::char_traits] ========= Compilation : END =========== -- ============================== Alex Vinokur mailto:alexvn AT go DOT to http://www.simtel.net/pub/oth/19088.html ==============================