fopen in C++ application?
-
wrote on 17 Feb 2019, 17:51 last edited by
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 ?
-
wrote on 17 Feb 2019, 17:59 last edited by
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?
-
wrote on 17 Feb 2019, 18:19 last edited by
If I declare it as global then nothing, but if it's declared in a function scope the file will automatically be closed when the object goes out of scope.
-
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. -
wrote on 17 Feb 2019, 18:23 last edited by
Yes, sorry, juggling lots of things atm, not thinking clearly.
8/9