Hello all, Please tell me is there way to read the <b>file descriptors</b> and give the contents to the <b>streambuf</b>, using streams, iam trying from all the way to achieve this but not able to succeed please tell me answer to this problem basically iam trying in this way,
in this way but this is not giving me answer because of
this casting, please help me how to read this file descriptor and give the result to streambuf , which other part of my project is using ,please help. iam using c++ for this if this is not a right forum please transfer this to the corresponding forum, because almost c++ is also a object oriented as java thats why i posted this here because reamins the same. [ November 26, 2007: Message edited by: vin Hari ]
The ifstream constructor is expecting the name of a file to open; casting an int file descriptor to a char* isn't going to magically give you the name of the file (of course). There's actually no way to do what you want built into the standard C++ libraries. You can either "roll your own" by subclassing streambuf (not recommended) or use a third-party library. You can't go wrong with the Boost libraries, many of which are being rolled into future C++ standards. Boost.iostreams has a file_descriptor_source class that lets you do what you want:
thank you for reply , so according to this discussion is there no way to open that file descriptor and redirect the output to the streambuf, is it the conclusion, if not in c++,also in c,\ even i tried directly ifstream f(fd); which result in error. i included <fstream.h>.
please clear me. [ November 26, 2007: Message edited by: vin Hari ]
author and iconoclast
Actually I said yes, there is a way. I think what you would do would be to implement a custom subclass of streambuf, which would use low-level C calls to work with the file descriptor. I imagine you could copy some code from the ifstream class to do this.
You could simply use the Boost library, which already provides a class (file_descriptor_source) which does exactly what you need. See the link I provided above.