我要使用fread(void *,int ,int,FILE *)读取一个文件。fread的第二和第三参数决定了读取的大小。可我怎么获得我要读取的文件的长度啊?如果随便写个很大的数,会不会出毛病啊。如何精确点?
解决方案 »
- 各位大师,这是什么语言??? Fortran吗?
- 关于棋牌室单个游戏的问题!!!
- 散分,很简单,偶初用VC6.0,碰到这样的问题。
- 关于CAsyncSocket和CSocket的疑问
- 关于打印预览
- 关于托盘菜单
- 关于foxmail特快专递的问题,分数不是问题
- 关于不规则区域填充颜色闪的问题。
- VC做的系统,拿到没有VC的机器上就完蛋了,有多少DLL要考的?
- 一个也许弱智问题:我在自己的类中添加一个CMainFrame * m_main成员,并且#include "MainFrm.h" 但是运行时出错,但我又在#include语句后加入class CMainFrame即可,为何???
- 每次都提示 "One or more files are out of date or do not exist "
- 访问数据库的两种方法,有什么优缺点?
virtual DWORD GetLength( ) const;
throw( CFileException );Return ValueThe length of the file.ResObtains the current logical length of the file in bytes, not the amount.CFile Overview | Class Members | Hierarchy ChartSee Also CFile::SetLength
char str[]="E:\\1.htm";
file=fopen(str,"r");
struct stat st;
if(stat(str,&st))cout<<"读取出错!\n";
int iFileSize = st.st_size; //获取文件大小
char *buf = new char[iFileSize+1];
memset(buf,'\0',iFileSize+1);
fread( buf, sizeof(char), iFileSize, file );
cout<<buf<<'\n'<<strlen(buf)<<'\n';
delete buf;