Skip to content

Instantly share code, notes, and snippets.

@philomuzzi
Created October 17, 2014 07:32
Show Gist options
  • Save philomuzzi/69793ad5ac7a60655d19 to your computer and use it in GitHub Desktop.
Save philomuzzi/69793ad5ac7a60655d19 to your computer and use it in GitHub Desktop.
一种从数字到字符串的转换方式
#include "iostream"
#include "string"
using namespace std;
string int2str(int n) {
char t[24];
int i = 0;
while (n) {
t[i++] = (n % 10) + '0';
n /= 10;
}
t[i] = 0;
return string(strrev(t));
}
int main() {
int n = 1312355;
string str = int2str(n);
cout<<str<<endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment