document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. //ex2. 將字串轉換成整數
  2. #include <iostream>
  3. #include <stdio.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     char str[10] = {\'1\',\'2\',\'3\',\'4\',\'5\',\'\\0\'};
  9.     int num;
  10.     int sum=0,i=0;
  11.     while(str[i]){
  12.         sum = sum*10 + str[i]-\'0\';
  13.         i++;
  14.     }
  15.     num=sum;
  16.     printf("num = %d\\n",num);
  17.  
  18.     system("pause");
  19.     return 0;
  20. }
');