C++ 获取文件大小及文件内容
BOOL GetFileSizeAndContent(const string& fileName, long& size, string& strContent)
{
FILE * pFile;
pFile = fopen( fileName.c_str(), "rb");
if (pFile == NULL)
{
return FALSE;
}
else
{
fseek(pFile, 0, SEEK_END);
size = ftell(pFile);
if (0 == size)
{
strContent = "";
fclose(pFile);
return TRUE;
strContent.resize(size);
fseek(pFile, 0, SEEK_SET);
fread((char*)&strContent[0], size, 1, pFile);
return TRUE ;
}
{
FILE * pFile;
pFile = fopen( fileName.c_str(), "rb");
if (pFile == NULL)
{
return FALSE;
}
else
{
fseek(pFile, 0, SEEK_END);
size = ftell(pFile);
if (0 == size)
{
size = 0;
strContent = "";
fclose(pFile);
return TRUE;
}
strContent.resize(size);
fseek(pFile, 0, SEEK_SET);
fread((char*)&strContent[0], size, 1, pFile);
fclose(pFile);
return TRUE ;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: C/C++ 获取文件大小
- 下一篇: PHP带参数(数组参数)方式打开另一个PHP文件