473,395 Members | 1,502 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,395 software developers and data experts.

How can I get a file descriptor from a c++ i/o stream?

Dear all,

Because of some reason, I must get a file descript from a c++ I/O stream,
for example: ifstream.

Under OpenUnix I have a function ifstream::fd (rdbuf->fd) to do this.
But in Linux, there is not a such function of ifstream class.
Is there not a such function in standard C++ ?
Or is there another way to get?

Thanks for your help.
Regards,
Thorsten

Jul 23 '05 #1
2 2446
Thorsten Knopel wrote:
Because of some reason, I must get a file descript from a c++ I/O stream,
for example: ifstream.

Under OpenUnix I have a function ifstream::fd (rdbuf->fd) to do this.
But in Linux, there is not a such function of ifstream class.
Is there not a such function in standard C++ ?
No. In general a stream doesn't have to have anything like a "file
descriptor" in it. It's implementation-defined how streams maintain
their association with whatever is considered "a file".
Or is there another way to get?


There can be something specific to your library implementation. Have
you tried looking in the docs or asking in a newsgroup for your OS?

V
Jul 23 '05 #2
Victor Bazarov wrote:
It's implementation-defined how streams maintain
their association with whatever is considered "a file".


It's unspecified, not implementation defined. The implementation doesn't
have to document what it does.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: andthen | last post by:
If I have a Class object, serialized or somehow stored, is there any way I can use it to create a .class file?
22
by: Bryan | last post by:
i'm curious to know how others handle the closing of files. i seem to always end up with this pattern even though i rarely see others do it. f1 = file('file1') try: # process f1 finally:...
6
by: pembed2003 | last post by:
Hi all, Given something like: std::ofstream out_file("path"); how do I extract the file descriptor from out_file? Is it possible? What I want is to extract the file descriptor and then pass...
6
by: Siddharth Taneja | last post by:
Hi, I have a very simple prg over here, trying to read the lines of a file #include <iostream> #include <fstream> #include <iostream> #include <string> using namespace std;
3
by: gipsy boy | last post by:
Given a file descriptor (from a network socket, for instance), I want to have an iostream that reads/writes to it, so I can push and read data in the traditional way : sockStream << "<some...
4
by: lynology | last post by:
I need help trying to figure why this piece of code gives me a "Bad File descriptor error" everytime I try to run it and invoke fflush. This piece of code simple outputs a char string to the output...
1
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C programming. FYI Although I have called this...
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...
13
by: thomas.mertes | last post by:
Hello Recently I discovered some problem. I have some C code which determines how many bytes are available in a file. Later I use this information to malloc a buffer of the correct size before...
15
by: =?ISO-8859-15?Q?L=E9na=EFc?= Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all, For some reasons, somewhere in a program, I'd like, if possible, to quickly parse a whole file before rewinding it and letting the...
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:
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
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.