Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ C4996 error with _wfopen function

Tags:

c++

file

I have 4 header files, all of them open data from a txt file with _wfopen(), like below:

FILE* file = _wfopen(L"data.txt",L"r,ccs=utf-8");

VC++ gives me an error C4996 but in one header file only, the other three have no error at all. How can I fix this ? UPDATE: My professor gave me this code.I compiled it and there's only C4996 warning.Since I need to reuse it, I created a new project and copy everything in his code into the new project.Then it gave me a C4996 error.

like image 641
Husky Avatar asked Dec 17 '25 01:12

Husky


1 Answers

A shallow search on the web indicates that you are using a deprecated function, raising, thus, the error C4996. As the example presents, you should be using the function _wfopen_s instead.

...
// Create an the xml file in text and Unicode encoding mode.
if ((fileHandle = _wfopen( L"_wfopen_test.xml",L"wt+,ccs=UNICODE")) == NULL) // C4996
// Note: _wfopen is deprecated; consider using _wfopen_s instead
{
    wprintf(L"_wfopen failed!\n");
    return(0);
}
...

The reason you have this error pointed only once for all of your four calls is that the compiler suppresses repeated errors.

Ref: http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx

like image 123
Rubens Avatar answered Dec 19 '25 17:12

Rubens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!