Created
September 26, 2013 12:37
-
-
Save ygabo/6713572 to your computer and use it in GitHub Desktop.
Own implementation of int to string (char array).
This file contains hidden or 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; | |
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