1

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

Adriano Repetti
  • 62,720
  • 18
  • 132
  • 197
Nayana Adassuriya
  • 21,894
  • 22
  • 97
  • 139

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
  • 69,456
  • 12
  • 118
  • 163