views:

46

answers:

2

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?

+2  A: 

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.

celavek
+1 This is good.
karlphillip
Well, I plan on running fstat() on the file descriptor, but I could use stat() on the actual filename.
Dan Snyder
+1  A: 

Take a look at open():

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

karlphillip