gpt4 book ai didi

c - fseek 一个新创建的文件

转载 作者:太空宇宙 更新时间:2023-11-04 06:22:45 25 4
gpt4 key购买 nike

我对 C 中的 fseek() 用法有疑问。我知道它可以设置由 fopen() 创建的文件描述符的偏移位置。但是它是否也可以设置新建文件的偏移位置呢?更具体地说,我可以:

  FILE * pFile;
pFile = fopen ( "myfile.txt" , "wb" ); //myfile.txt doesn't exit before
fseek ( pFile , 1024*1024*1024 , SEEK_SET);
fclose(pFile);

它会创建一个大小为 1 GB 且没有内容的文件吗?或者我应该至少写点东西来创建这个 1 GB 的文件吗?

最佳答案

http://en.cppreference.com/w/c/io/fseek

POSIX allows seeking beyond the existing end of file. If an output is performed after this seek, any read from the gap will return zero bytes. Where supported by the filesystem, this creates a sparse file.

关于c - fseek 一个新创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31642389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com