我可以帮您进行翻译。以下是关于it技术的内容:
我的代码中出现了一个非常奇怪的stat.h问题。
在代码顶部,我有这些声明:
#include <sys\types.h>
#include <sys\stat.h>
函数原型:
int FileSize(string szFileName);
最后,函数本身的定义如下:
int FileSize(string szFileName)
{
struct stat fileStat;
int err = stat( szFileName.c_str(), &fileStat );
if (0 != err) return 0;
return fileStat.st_size;
}
当我尝试编译这段代码时,出现了错误:
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'
来自这个帖子:如何在C语言中获取文件大小? 我认为这段代码应该是有效的,但我无法弄清楚为什么它不能编译。有人能发现我做错了什么吗?