Convert it to a file descriptor using .fd() and then to a FILE stream using fdopen().
See here for more detailed information.
Adrian
Did you try the code, it dont work for me. I tried this
- int main ( )
-
{
-
fstream fs( "test.txt", ios::in );
-
if( fs.is_open() )
-
return 0;
-
FILE* f = fs.fd();
-
return 0;
-
}
I get this error
error C2039: 'fd' : is not a member of 'std::basic_fstream<_Elem,_Traits>'
I need FILE pointer from a C++ stream because, I need to lock the file and I came across this function
- void _lock_file(
-
FILE* file
-
);
which takes FILE* but in my application I make use of C++ stream to read and write to a file which I cannot change.
Can you correct me if I'm doing something wrong above....
Thanks for your understanding