473,545 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2467
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
2044
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
31251
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: f1.close() which explicitly closes f1
6
6261
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 it to flock like: flock(???, LOCK_EX);
6
1765
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
7060
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 stuff>" < "\r\n" How is this possible with the standard header files? I need this because my objects have xml'ed << operators, but now I can't figure...
4
5983
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 stream. What ends up happening instead is that when outputting the first character string to the channel CG_cdukeypad_CHA.Scrpad, its gives the...
1
64028
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 article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts,...
5
5246
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 descriptor)? Thank you.
13
4468
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 I read the bytes. Determining the number of bytes available in a file is done in 5 steps: 1. Use tell(aFile) to get the current position.
15
3165
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 full analysis start. My problem is that the FILE* I want do parse has been fopen'ed far away from where I am and I don't know in which MODE my FILE*...
0
7928
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7775
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5344
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4963
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1030
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.