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

T

Thorsten Knopel

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
 
V

Victor Bazarov

Thorsten said:
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
 
P

Pete Becker

Victor said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top