下面是C语言文件相关操作的代码。
#include<stdio.h>
#include<iostream>
int main()
{
// 打开文件
FILE *pFile = fopen("..\\exampleFolder\\exampleFile", "rb");
if (NULL == pFile)
{
exit(1);// 头文件<iostream>
}
// 读取文件字符
char cFileContent;
while (fscanf(pFile, "%c", &cFileContent) != EOF)
{
printf("%c\n", cFileContent);
}
//获取文件长度
fseek(pFile, 0, SEEK_SET);
fseek(pFile, 0, SEEK_END);
long longBytes = ftell(pFile);// longBytes就是文件的长度
// 关闭文件
fclose(pFile);
return 0;
}

本文详细介绍了使用C语言进行文件相关操作的方法,包括文件的打开、读取、获取长度及关闭等基本步骤。

被折叠的 条评论
为什么被折叠?



