473,394 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to read from file descriptors.

Hello all,

Hello all,
iam working on some project in which i need to open a file descriptor and send it to the streambuf,
which can be done like this

Expand|Select|Wrap|Line Numbers
  1. ifstream f(fd);
  2. streambuf * buf2=f.rdbuf();
but main problem is that they are casting to

Expand|Select|Wrap|Line Numbers
  1. ifstream f((const char *)fd)
  2. streambuf * buf2=f.rdbuf();
because of which the file is not getting opened ,if i remove that leads to error there are using some conventions

there are many ways are also there like

Expand|Select|Wrap|Line Numbers
  1. File *ptr=fdopen(fd);
which is successfull and returning the value.
but i want the the output to be given in streambuf which other parts of my project is using,
can u tell me is there any way to convert the file pointer to the streambuf or is there anyway of reading the file so that the output will result in the streambuf

please help me.
Nov 25 '07 #1
3 7101
9,208 Expert Mod 8TB
This compiles:
Expand|Select|Wrap|Line Numbers
  1. char* fd = "hello";
  2. ifstream f((const char *)fd);
  3. streambuf * buf2=f.rdbuf();
I guess I don't see your problem.

However, you should avoid the C file system: fopen, fread, etc.... C++ uses inheritance with the streams and by using the C file system you lose all the advantages of C++ streams and go back to the file handling of 1972.

As a general rule, avoid C in C++.
Nov 25 '07 #2
Hello thank u for reply ,
but as my question is here file descriptor not the character array,
ifstream s((char *)fd);
here the fd returns interger value, so is there anyway of getting the contents of fd so that they can be stored in the streambufer, please help me.
Nov 26 '07 #3
9,208 Expert Mod 8TB
ifstream s((char *)fd);
here the fd returns interger value, so is there anyway of getting the contents of fd so that they can be stored in the streambufer, please help me.
fd is a function??

fd is a function that returns an int??

Maybe you better show me what fd is. In my example fd was a C-string containing the disc file name to open.
Nov 26 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

by: François Pinard | last post by:
This question is a bit technical, but hopefully, this list will offer me good hints or nice solutions. Happily enough for me, it often does! :-) I would need to recognise and play with...
by: Uwe Mayer | last post by:
Hi, I use select() to wait for a file object (stdin) to become readable. In that situation I wanted to read everything available from stdin and return to the select statement to wait for more. ...
by: John Marshall | last post by:
Hi, Does anyone see a problem with doing: data = file("tata").read() Each time this is done, I see a new file descriptor allocated (Linux) but not released. 1) Will there ever be a point...
by: Antoon Pardon | last post by:
Can anyone explain why descriptors only work when they are an attribute to an object or class. I think a lot of interesting things one can do with descriptors would be just as interesting if the...
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to...
by: Roman Mashak | last post by:
Hello, All! I implemented simple program to eliminate entry from the file having the following structure (actually it's config file of 'named' DNS package for those who care and know): ...
by: poddar | last post by:
Hi, I am new to this group. I had just one small question Is it possible to get the file name back from file descriptor. i.e. I have written a function to overload the libc write using...
by: Matt Brandt | last post by:
I am trying to get multiple threads to lock specific regions of a file. However, since each thread has the same PID, it appears that a lock by one thread does not block another thread from the same...
by: yinglcs | last post by:
I have a c/c++ program in linux. I would like to know if I kill my program (e.g. exit(1)), will it release all the file descriptors my program held (regardless if I call close(fd) of each file...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.