Question

Is there any way to access the file descriptor of a file opened in c++? So ...

 #include <iostream>
 #include <fstream>
 using namespace std;

 int main() {
      ifstream inputFile( "file.txt",ios::in );
      cout << inputFile.fileDesc << endl;//made up call
      return 0;
 }

The question is, does something like fileDesc exist for ifstreams? If not how would I go about doing this?

Was it helpful?

Solution

If you're trying to get to the FILE* from the stream then the answer is basically "you can't" as stated by more enlightened people than me here.

OTHER TIPS

Take a look at open():

The open function creates and returns a new file descriptor for the file named by filename.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top