C得到文件的大小
#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
FILE* fp = NULL;
int nFileLen = 0;
fp = fopen("Test.jpg", "rb");
if (fp == NULL)
{
cout << "can't open file" << endl;
return 0;
}
fseek(fp,0,SEEK_END); //定位到文件末
if ((nFileLen = ftell(fp))<1)//文件长度
{
fclose(fp);
return 0;
}
char* data = (char *)malloc(sizeof(char)*(nFileLen+1));
if (NULL == data)
{
fclose(fp);
return 0;
}
fread(data, nFileLen, 1, fp);
free(data);
fclose(fp);
return 0;
}
)
return 0;
}