fopen in C++ application?
-
I want to use fopen, I've included the headers:
#include <stdio.h> #include <stdlib.h>
In my source I have declared:
FILE* fp = fopen("file.txt", "rt");
I'm getting:
no matching function for call to 'fopen'
Why? I thought fopen was part of the standard C library?
I need a file handing routine that I can translate the returned file pointer into a handle and then back from a handle to a file pointer so I can pass the handle back and forth between the application and another module.
-
Hi,
The include is <cstdio>.
Since you are using Qt, why not use QFile ?
-
Yes you can get it but if the QFile goes out of scope, the handle won't be valid anymore.
What is your exact use case ?
-
I'm writing an application that will provide native functions and access to the OS GUI it includes services such as file access and database access. I've completed the database service which works well. I want to provide file access which is as efficient a possible, so once the file is opened I want it to stay opened until a request is sent to close the file.
-
So what's wrong with a QFile object then?
-
You're aware you can create any object on the heap?
QFile *f = new QFile ...
You only have to make sure to delete it once you don't need it anymore.