boost::filesystem::file_size()
returns boost::uintmax_t
. So, How to convert boost::uintmax_t
to std::string
?
Asked
Active
Viewed 1,077 times
1

Adriano Repetti
- 65,416
- 20
- 137
- 208

Nayana Adassuriya
- 23,596
- 30
- 104
- 147
-
1I'm guessing both `std::to_string` and `boost::lexical_cast` do the job. – chris Jan 29 '13 at 08:14
-
2Some suggestions here: http://stackoverflow.com/questions/10516196/append-an-int-to-a-stdstring/10516313#10516313 – hmjd Jan 29 '13 at 08:15
-
std::to_string not works but boost::lexical_cast works. thank you experts! – Nayana Adassuriya Jan 29 '13 at 09:40
1 Answers
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