boost::filesystem::file_size()
returns boost::uintmax_t
. So, How to convert boost::uintmax_t
to std::string
?
Well, you can use some simple approach like:
boost::lexical_cast<std::string>(size);
Or manually using the 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; 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.
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. In which case have a look at libkibi .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.