annoying.. filebuf's

Roberto Diaz rdiazmartin@vivaldi.dhis.org
Mon Jun 18 18:52:00 GMT 2001


Hi..

I had been wondering like a hell how could I attatch a file descriptor to
a stream object.. I was looking at GNU extensions.. but now I find this:

/usr/include/g++-3/streambuf.h:    filebuf();
/usr/include/g++-3/streambuf.h:    filebuf(int fd);
/usr/include/g++-3/streambuf.h:    filebuf(int fd, char* p, int len);

And this code works:

#include <iostream>
#include <cstdlib>
#include <string>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int
main ()
{
  // we open the file
  int f = open ("./prueba1.tmp", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
  // we create a buffer
  filebuf mybuffer (f);
  // now the stream
  ostream os (&mybuffer);
  // so we write
  string s = "this is a string ";
  os << "OK lets see whats going on here!! " 
     << s << 4 << endl;
  exit (EXIT_SUCCESS);
}

// so simple? :?????????????????


I suppose it is the same easy for sockets.. isnt it? 

OK... :???

Regards

Roberto

------------------------------------------------------------------------
Roberto Diaz <rdiazmartin@vivaldi.dhis.org>
http://vivaldi.dhis.org
Powered by GNU running on a Linux kernel.
Powered by Debian (The real wonder)

Concerto Grosso Op. 3/8 A minor
Antonio Vivaldi (so... do you need beautiful words?)
------------------------------------------------------------------------



More information about the Libstdc++ mailing list