Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/128.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ fseek现在支持大文件_C++_64 Bit_Large Files_Fseek - Fatal编程技术网

C++ fseek现在支持大文件

C++ fseek现在支持大文件,c++,64-bit,large-files,fseek,C++,64 Bit,Large Files,Fseek,现在看来,至少在我的实现中,fseek自然支持大文件,而不需要fseek64、lseek或一些奇怪的编译器宏 这是什么时候发生的 #include <cstdio> #include <cstdlib> void writeF(const char*fname,size_t nItems){ FILE *fp=NULL; if(NULL==(fp=fopen(fname,"w"))){ fprintf(stderr,"\t-> problems op

现在看来,至少在我的实现中,fseek自然支持大文件,而不需要fseek64、lseek或一些奇怪的编译器宏

这是什么时候发生的

#include <cstdio>
#include <cstdlib>
void writeF(const char*fname,size_t nItems){
  FILE *fp=NULL;
  if(NULL==(fp=fopen(fname,"w"))){
    fprintf(stderr,"\t-> problems opening file:%s\n",fname);
    exit(0);
  }
  for(size_t i=0;i<nItems;i++)
    fwrite(&i,sizeof(size_t),1,fp);
  fclose(fp);
}
void getIt(const char *fname,size_t offset,int whence,int nItems){
  size_t ary[nItems];
  FILE *fp = fopen(fname,"r");
  fseek(fp,offset*sizeof(size_t),whence);
  fread(ary,sizeof(size_t),nItems,fp);

  for(int i=0;i<nItems;i++)
    fprintf(stderr,"%lu\n",ary[i]);
  fclose(fp);
}


int main(){
  const char * fname = "temp.bin"; 
  writeF(fname,1000000000);//writefile
  getIt(fname,999999990,SEEK_SET,10);//get last 10 seek from start
  getIt(fname,-10,SEEK_END,10);//get last 10 seek from start
  return 0;
}
#包括
#包括
void writeF(常量字符*fname,大小单位){
FILE*fp=NULL;
if(NULL==(fp=fopen(fname,“w”)){
fprintf(stderr,“\t->打开文件时出现问题:%s\n”,fname);
出口(0);
}

for(size_t i=0;i
9999999 0
是一个正常的整数,完全适合32位。不过,我不相信您会侥幸逃脱:

getIt(fname,99999999990LL,SEEK_SET,10);

Linux x86-64从一开始就有了大文件支持(LFS);并且不需要任何特殊的宏等来启用它-传统的
fseek()
)和LFS
fseek64()
都已经使用了64位
off\u t

Linux i386(32位)通常默认为32位
off\u t
,否则会中断大量应用程序-但您可以通过检查
\u FILE\u OFFSET\u BITS
宏的值来测试环境中定义的内容

有关Linux大文件支持的完整详细信息,请参阅。

签名为

int fseek ( FILE * stream, long int offset, int origin );
因此,范围取决于
long
的大小


在某些系统上它是32位的,而在其他系统上它是64位的。我以为fseek只能达到2GB,但我在这里看不到2GB的文件。@monkeyking-IOW,1000000000=1000000000和9999999999 0=99999999 0,这两个都不是>2GBAlso,你没有提到平台…duh