use*_*171 6 c++ filesize stat incomplete-type
我对stat.h有一个非常奇怪的问题
在我的代码的顶部,我有声明:
#include <sys\types.h>
#include <sys\stat.h>
Run Code Online (Sandbox Code Playgroud)
和功能原型:
int FileSize(string szFileName);
Run Code Online (Sandbox Code Playgroud)
最后,函数本身定义如下:
int FileSize(string szFileName)
{
struct stat fileStat;
int err = stat( szFileName.c_str(), &fileStat );
if (0 != err) return 0;
return fileStat.st_size;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译此代码时,我收到错误:
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'
Run Code Online (Sandbox Code Playgroud)
从这个线程:我怎样才能在C中获得文件的大小? 我认为这段代码应该可行,我无法弄清楚为什么它不能编译.谁能发现我做错了什么?
你\应该是你/的,还是我对你的环境感到困惑?
UNIX MAN页面:
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
int stat(const char *restrict path, struct stat *restrict buf);
Run Code Online (Sandbox Code Playgroud)
如果你在Windows上(我猜你可能是因为它\),那么我无法帮助,因为我甚至不知道那个stat.