document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //ex1. 怎樣將整數轉換成字串,並且不用函式itoa.
  2. #include <iostream>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int num=12345;
  9.     char temp[100], str[100];
  10.     int digits=0;
  11.  
  12.     for(int i=0,tempNum=num; tempNum>0;i++){
  13.         temp[i]=tempNum%10+\'0\';
  14.         tempNum /= 10;
  15.         digits++;
  16.     }
  17.  
  18.     for(int i=0;i<digits;i++){
  19.         str[digits-i-1]=temp[i];
  20.     }
  21.     str[digits]=\'\\0\';
  22.     printf("string = %s\\n",str);
  23.  
  24.     system("pause");
  25.     return 0;
  26. }
');