Last active
August 14, 2018 08:21
-
-
Save zziz/fb2570cccd030dc469fb4996613d484f to your computer and use it in GitHub Desktop.
Alternative to C++ to_string if not available in platform. It happens :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::string to_str(int num){ | |
std::string str = ""; | |
std::string nums[10]; | |
nums[0] = "0"; nums[1] = "1"; nums[2] = "2"; nums[3] = "3"; nums[4] = "4"; | |
nums[5] = "5"; nums[6] = "6"; nums[7] = "7"; nums[8] = "8"; nums[9] = "9"; | |
if(num == 0) return nums[0]; | |
int d = pow(10, 1.0 + floor(log10(num))); | |
while (d /= 10) str += nums[(num / d) % 10]; | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment