This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
annoying.. filebuf's
- To: Linux C++ Programming <tuxCPProgramming at listbot dot com>
- Subject: annoying.. filebuf's
- From: Roberto Diaz <rdiazmartin at vivaldi dot dhis dot org>
- Date: Tue, 19 Jun 2001 03:52:21 +0200 (MEST)
- cc: libstdc++ <libstdc++ at gcc dot gnu dot org>
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?)
------------------------------------------------------------------------