[英]How to convert boost::uintmax_t to std::string
boost::filesystem::file_size()
returns boost::uintmax_t
. boost::filesystem::file_size()
返回boost::uintmax_t
。 So, How to convert boost::uintmax_t
to std::string
? 因此,如何将
boost::uintmax_t
转换为std::string
?
Well, you can use some simple approach like: 好吧,您可以使用一些简单的方法,例如:
boost::lexical_cast<std::string>(size);
Or manually using the stringstream: 或手动使用stringstream:
static_cast<std::stringstream>(std::stringstream() << size).str()
The operator for numbers is a member, so it should work on temporary even in C++03; 数字运算符是成员,因此即使在C ++ 03中,它也应在临时函数上起作用; some other overloads are free functions and in C++03 those don't accept temporary, but you can use
std::stringstream().flush()
, which returns lvalue reference and than all operator<<
overloads work. 其他一些重载是自由函数,在C ++ 03中,这些重载不接受临时函数,但是您可以使用
std::stringstream().flush()
,它返回左值引用,并且所有operator<<
重载都可以工作。
But it's not just plain number. 但这不仅是简单的数字。 It's file size.
它是文件大小。 So it's quite likely you should be rounding it and handling kB/MB/GB/KiB/MiB/GiB units.
因此,很可能您应该四舍五入并处理kB / MB / GB / KiB / MiB / GiB单位。 In which case have a look at libkibi .
在这种情况下,请查看libkibi 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.