1#include <iostream>2#include <windows.h>3 using namespacestd;4 5 6 /*format According to the size of the file7 *@[in] Length of llbytes file (B)8 *@[out] Pszsize buffer9 *@[in] Clen buffer lengthTen */ One ABOOL Filesizetostringa (Longlong llbytes,Char*pszsize, DWORD cLen) - { - Doublebytes = (Double) llbytes; theDWORD Citer =0; - Char* pszunits[] = {("B"), ("KB"), ("MB"), ("GB"), ("TB") }; -DWORD cunits =sizeof(pszunits)/sizeof(pszunits[0]); - + //move from bytes to KB, to MB, to GB and so on diving by 1024x768 - while(Bytes >=1024x768&& Citer < (cunits-1)) + { ABytes/=1024x768; atciter++; - } -_snprintf_s (Pszsize, CLen, _truncate, ("%.2f%s"), Bytes, pszunits[citer]); - returnTRUE; - } - in intMain () - { to Charsztext[ the]; +Filesizetostringa (23156, Sztext, the); - thecout <<"Sztext:"<< Sztext <<Endl; * $ GetChar ();Panax Notoginseng return 0; -}
C + + File size formatting