To get rid of your error message, you need to fix the issue that is generating warning.
If you compile this code:
#include "stdafx.h"
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
FILE* p_file = NULL;
std::wstring tempFileName = L"c:\\test.txt";
p_file=_wfopen(tempFileName.c_str(),L"r");
if(!p_file)
{
perror("Open failed.");
return 0;
}
fseek(p_file,0,SEEK_END);
fclose(p_file);
return 0;
}
You will get this warning:
warning C4996: '_wfopen': This function or variable may be unsafe. Consider using _wfopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
So, listen what it says, and do the following:
#include "stdafx.h"
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
FILE* p_file = NULL;
std::wstring tempFileName = L"c:\\test.txt";
_wfopen_s(&p_file, tempFileName.c_str(),L"r");
if(!p_file)
{
perror("Open failed.");
return 0;
}
fseek(p_file,0,SEEK_END);
fclose(p_file);
return 0;
}
There is a way to turn off this warning by putting _CRT_SECURE_NO_WARNINGS
in Project Properties
-> C/C++
-> Preprocessor
-> Preprocessor Definitions
, but you should always prefer safe alternatives to these functions.
Also, before fseek
you should check if your p_file pointer is NULL
.