🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #399

fstream filbuf problem

#399
From: Michael.Conner
Date: Tue, 29 Sep 1992 16:00
32 lines
1323 bytes

I need to get an fstream with known buffer size.  I am trying
to do this by getting the filebuf through rdbuf() and then setting
the buffer, using setbuf(char *, int ).  I keep getting a bus error
when I try to actually output something. Is this the wrong way to
do this ?  If so, shouldn't rdbuf() return a const filebuf *. Is
there a work around for this?  Help!  

I'm using gcc 2.2.2 on INTERACTIVE UNIX Sys V/386 Rel 3.2

Here's the code:

#include <iostream.h>
#include <fstream.h>

main (){
   fstream x;
   (x.rdbuf())->setbuf(  new char[4096], 4096 );
   if (x.fail()) cout << "fail set(1)" << endl; 
   x.open("somefile", ios::in | ios::out );
   if (x.fail()) cout << "fail set(2)" << endl; 
   cout << "----" << endl;
   x << "some output";
   cout << "++++" << endl;
}

Here's the results:
----
Bus error - core dumped
-- 
Michael.Conner@mixcom.com
Technical Details
Message-ID: <1992Sep29.160050.20638@mixcom.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!spool.mu.edu!mixcom.com!Michael.Conner

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.help
Path: arc1-ca.pugleaf.net!sparky!uunet!stanford.edu!agate!spool.mu.edu!mixcom.com!Michael.Conner
From: Michael.Conner <Michael.Conner@mixcom.mixcom.com>
Subject: fstream filbuf problem
Organization: Milwaukee Internet Xchange BBS, Milwaukee, WI U.S.A.
Distribution: usa
Date: Tue, 29 Sep 1992 16:00:50 GMT
Message-ID: <1992Sep29.160050.20638@mixcom.com>
Sender: ddyydd@mixcom.com (Michael J. Conner)
Lines: 32