Fopen_s not allowed in Ubuntu
I want to open a file, so I am using fopen_s function under ubuntu. Although I #include <stdio.h>
have as stated here http://en.cppreference.com/w/c/io/fopen , I get that the error function was not declared in scope. Please help me what I am doing wrong and how to do it?
FILE *fp;
fopen_s(&fp, strFilename.c_str(), "rb");
if (fp == NULL){
cout << "cannot open " << strFilename.c_str();
return false;
}
fclose(fp);
source to share
Searching for glibc on Linux finds no evidence that fopen_s
() is implemented in glibc on Linux.
I don't mention fopen_s
() in the POSIX spec . It seems to me that fopen_s
() is a non-portable library function implemented only in Microsoft Windows.
source to share
Try using fopen ()
#ifdef __unix
#define fopen_s(pFile,filename,mode) ((*(pFile))=fopen((filename), (mode)))==NULL
#endif
reference: Is there a way to use fopen_s () with GCC, or at least create a #define about it?
source to share