I have a very strange problem with stat.h
At the top of my code, I have declarations:
#include <sys\types.h> #include <sys\stat.h>
And the function prototype:
int FileSize(string szFileName);
Finally, the function itself is defined as follows:
int FileSize(string szFileName) { struct stat fileStat; int err = stat( szFileName.c_str(), &fileStat ); if (0 != err) return 0; return fileStat.st_size; }
When I try to compile this code, I get an error message:
divide.cpp: In function 'int FileSize(std::string)': divide.cpp:216: error: aggregate 'stat fileStat' has incomplete type and cannot be defined divide.cpp:217: error: invalid use of incomplete type 'struct stat' divide.cpp:216: error: forward declaration of 'struct stat'
From this topic: How to get file size in C? I think this code should work, and I cannot understand why it does not compile. Can anyone determine what I am doing wrong?
source share