Skip to content

Instantly share code, notes, and snippets.

@ygabo
Created September 26, 2013 12:37
Show Gist options
  • Save ygabo/6713572 to your computer and use it in GitHub Desktop.
Save ygabo/6713572 to your computer and use it in GitHub Desktop.
Own implementation of int to string (char array).
#include <iostream>
#include <string>
using namespace std;
int main(){
int x = -1234;
string y;
int temp;
int templeft;
if ( x < 0 ) templeft = -1 * x;
else templeft = x;
while( templeft > 0 ){
temp = templeft %10;
y = static_cast<char>('0'+ temp) + y;
templeft = templeft/10;
}
if( x < 0 )
y = '-' + y;
cout << y << endl;
cout << endl << "done." << endl;
std::cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment