C ++ stat.h is an incomplete type and cannot be defined

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?

+6
source share
1 answer

Do you assume that \ / or am I just confused in your environment?

UNIX MAN Page:

  #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> int stat(const char *restrict path, struct stat *restrict buf); 

If you are on Windows (which I assume you are due to \ ), then I cannot help because I did not even know that I had a stat .

+5
source

Source: https://habr.com/ru/post/908465/


All Articles