Bool setfilelength (const char * filepath, off_t length) {# ifdef win32system: IO: filestream * file = system: IO: file: open (length, file :: openmode, file: allaccess); If (! File) {return false ;}/// <summary> // expression call file-> setlength () method // The underlying implementation of this method is to call ntsetinformationfile // and set the file length through the file_end_of_file_information structure. The advantage of this method is that you can directly set the length of the Longlong type // /</Summary> file-> length = length; delete file; return true; // reference // http://msdn.microsoft.com/en-us/library/ff567096 (V = vs.85 ). aspx # elseint FD = open (filepath, o_rdwr ); /// <summary> ///-1 if an error occurred // </Summary> If (FD =-1) {return false ;} /// <summary> // on success, zero is returned. on error,-1 is returned, and errno is set appropriately. /// </Summary> return ftruncate (FD, length) = 0; // references // optional}
PS: This method only supports Windows and Linux platforms.