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.

10
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

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

Code:
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

Code:
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
weaknessforcats
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();
  4.  
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
vin029
10
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
weaknessforcats
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

2
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...
1
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. ...
5
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...
14
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...
5
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...
6
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...
36
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): ...
13
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...
15
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
0
BarryA
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...
0
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...
0
marktang
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,...
0
jinu1996
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...
0
tracyyun
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.