1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <string> using namespace std; const string FReadAll ( const char* pszPath ) { long lFileSize = 0; size_t iReadLength = 0; char* ptrBuff = 0; FILE* stream = 0; string strRet; stream = fopen ( pszPath, "r+t" ); if ( 0 == stream ) return ""; fseek( stream, 0, SEEK_END ); lFileSize = ftell ( stream ); fseek( stream, 0, SEEK_SET ); ptrBuff = new char[lFileSize+1]; iReadLength = fread ( ptrBuff, sizeof ( char ), (int)lFileSize, stream ); ptrBuff[iReadLength] = '\0'; strRet = ptrBuff; fclose ( stream ); return strRet; } |