Skip to content

Instantly share code, notes, and snippets.

@zziz
Last active August 14, 2018 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zziz/fb2570cccd030dc469fb4996613d484f to your computer and use it in GitHub Desktop.
Save zziz/fb2570cccd030dc469fb4996613d484f to your computer and use it in GitHub Desktop.
Alternative to C++ to_string if not available in platform. It happens :)
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