C++ C++;stat.h类型不完整,无法定义

C++ C++;stat.h类型不完整,无法定义,c++,filesize,stat,incomplete-type,C++,Filesize,Stat,Incomplete Type,我对stat.h有一个非常奇怪的问题 在我的代码顶部,我有声明: #include <sys\types.h> #include <sys\stat.h> 最后,函数本身定义如下: int FileSize(string szFileName) { struct stat fileStat; int err = stat( szFileName.c_str(), &fileStat ); if (0 != err) return 0;

我对stat.h有一个非常奇怪的问题

在我的代码顶部,我有声明:

#include <sys\types.h> 
#include <sys\stat.h> 
最后,函数本身定义如下:

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'
从该线程:
我认为这段代码应该可以工作,但我不明白为什么它不能编译。有人能看出我做错了什么吗?

你的
\
应该是
/
,还是我只是对你的环境感到困惑

UNIX手册页:

 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>

 int stat(const char *restrict path, struct stat *restrict buf);
#包括
#包括
#包括
int stat(const char*restrict path,struct stat*restrict buf);

如果你在Windows上(我猜你可能是因为
\
),那么我也帮不上忙,因为我甚至不知道had
stat

啊,问题是\而不是代码的include部分。在修复之后,问题得到了解决。虽然我使用了正确的路径分隔符,但我也遇到了同样的问题。我在Windows上使用MinGW进行编译,编译器有sys/stat.h文件,声明了struct stat和function stat。还有什么想法吗?
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>

 int stat(const char *restrict path, struct stat *restrict buf);