Standard way:
std::string uint64_to_string( uint64 value ) { std::ostringstream os; os << value; return os.str(); }
If you need an optimized method, you can use it:
void uint64_to_string( uint64 value, std::string& result ) { result.clear(); result.reserve( 20 ); // max. 20 digits possible uint64 q = value; do { result += "0123456789"[ q % 10 ]; q /= 10; } while ( q ); std::reverse( result.begin(), result.end() ); }
Frunsi
source share