0
Whenever I try to use the fopen command Visual Studio returns me an error saying that such command is insecure, and that I should use fopen_s, but in case I do not know what direction to take with fopen_s.
0
Whenever I try to use the fopen command Visual Studio returns me an error saying that such command is insecure, and that I should use fopen_s, but in case I do not know what direction to take with fopen_s.
0
According to the job documentation, the code snippet using fopen
:
fp = fopen(filename, mode);
can be rewritten as
errno_t error_code = fopen_s(&fp, filename, mode);
in which error_code
is equal to 0
if the operation is successful or contains an error code if the operation fails. Note that the first argument of fopen_s
is FILE**
, i.e., a pointer to a pointer. It is therefore necessary to pass the address of fp
as &fp
.
With the exception of handling possible errors you should now consider the value of error_code
, the rest of the code should work the same way it would if the function was used fopen
.
I realized I didn’t answer your question directly. If you really want to use fopen
(for portability reasons, for example), set the macro _CRT_SECURE_NO_DEPRECATE
before including stdio.h
:
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
Thank you very much!
Browser other questions tagged c++
You are not signed in. Login or sign up in order to post.
Since you are programming in C++ it would not be better to use a stream?
– Maniero
But how would I fit a stream into a Keylogger?
– Lawliet
Also I could never use the VS keeps filling the patience with this
– Sveen
Yes, but I understand the VS, fopen can be manipulated, so the fopen_s, but the structures of the code change and I do not know how to proceed
– Lawliet
Just as a hint, use
fopen_s
is decommissioned for portability reasons. The best solution would be just what @Maniero said and follow up with a stream solution that is normal for C++. There’s another hint "don’t complicate something simple".– Isac