牛骨文教育服务平台(让学习变的简单)
博文笔记

C++ 获取文件大小及文件内容

创建时间:2018-03-22 投稿人: 浏览次数:125
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)
{

                        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 ;
}
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。