Ok let's try that again (hope i read the question right this time!) using namespace std; using namespace __gnu_cxx;
....
int fd = open("test.txt", O_RDONLY);
stdio_filebuf<char> in(fd, ios::in, false, 1024);
istream inf(&in);
string str;
while(!inf.eof()) {
inf >> str;
cout << str << endl;
}
close(fd);
This reads a file using standard c++ streams created from a POSIX file
descriptor. Compiled using gcc 3.2.2.
HTH this time....
** On Thu Mar 11, 2004 at 12:04:06AM +1100, [EMAIL PROTECTED] ([EMAIL PROTECTED])
wrote:
> On Wed, 10 Mar 2004 22:40:44 +1100
> Lucas King <[EMAIL PROTECTED]> wrote:
>
> > hello,
> >
> > a somewhat technical question - i am trying to associate a file
> > descriptor with a file pointer using the C++ fstream class. this
> > function is an extension to the C++ library.
> >
> > in the documentation that i downloaded from the WEB
> > (http://nf.apac.edu.au/facilities/sc/compaq_mirror3/progtool/cplus/basic_fstream_3c__std.htm)
>
>
> That doco is for the RogueWave library, which is not necessarily in the standard.
> In fact I'm pretty sure it's not, because file descriptors are a unix
> thing not a language (c++) thing
>
> > it shows a constructor, explicit basic_fstream(fd). i take this to mean
> > that it can be done. however, it does not provide an example on how to
>
> I've been wanting to do a similar thing, and the thing to use
> is a gnu extension. Beginning with g++ 3.1, you should use
> a class __gnu_cxx::stdio_filebuf which is defined in the include file
> <ext/stdio_filebuf.h> (aka /usr/include/g++/ext/stdio_filebuf.h)
>
> But I'm right in the middle of doing this and haven't got anything working
> at the moment. The net is a bit short on examples!
>
>
> Matt
> PS. I want this so I can popen nicely from within c++.
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
pgp00000.pgp
Description: PGP signature
-- SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/ Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
