C++文件字节数转不同单位字符串表示
std::string size_conv(uint64_t size)
{
char text[16] = { 0 };
double bsize = size;
char* btypes[] = { "B","KB","MB","GB","TB","PB","EB","ZB","YB","BB","NB","DB", };
int n = 0;
for (; bsize >= 1024; bsize /= 1024, n++);
if (n >= 0 && n < (sizeof(btypes) / sizeof(*btypes)))
snprintf(text, sizeof(text) / sizeof(*text), "%.2f%s\n", bsize, btypes[n]);
return text;
}