Quick actions

cmd+k|ctrl+k

Navigation

Languages

int to str

Snippet info

Language

Cpp

Visibility

public

Author

xealgo

Created

2017-05-09T22:30:46Z

Updated

2017-05-09T22:30:46Z

#include <iostream>
#include <string>

using namespace std;

int main() {
    int num = 12345;
    int n = num;
    char buf[255] = {};
    
    int i = 0; 
    
    while ((n+1/10) != 0) {
        int r = n % 10;
        n /= 10;
        int x = (r + '0');
        buf[i] = (char)x;
        ++i;
    }
    
    string str = "";
    int size = num % 10;
    
    for (int j = size-1; j >= 0; --j) {
        str += buf[j];
    }
    
    str = "number is: " + str;
    
    cout << str << endl;
    return 0;
}
INFO