1

boost::filesystem::file_size() returns boost::uintmax_t. So, How to convert boost::uintmax_t to std::string?

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
Nayana Adassuriya
  • 23,596
  • 30
  • 104
  • 147

1 Answers1

1

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.

Jan Hudec
  • 73,652
  • 13
  • 125
  • 172