Created
October 17, 2014 07:32
-
-
Save philomuzzi/69793ad5ac7a60655d19 to your computer and use it in GitHub Desktop.
一种从数字到字符串的转换方式
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
#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