返回列表 發帖
本帖最後由 楊惇翔 於 2023-5-13 20:54 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="123.45.6789";
  8.     str +=".";
  9.     string n[10];
  10.     int index=0;
  11.     string tmp="";
  12.     for(int i=0;i<str.length();i++)
  13.     {
  14.         if(str[i]=='.')
  15.         {
  16.             n[index]=tmp;
  17.             tmp="";
  18.             index++;               
  19.         }      
  20.         else
  21.         {
  22.             tmp+=str[i];   
  23.         }
  24.     }
  25.     for(int i=0;n[i]!="";i++)
  26.         cout<<n[i]<<endl;
  27.     system("pause");
  28.     return 0;   
  29. }


  30. 123.45.6789.
  31. tmp=6789

  32. n[0]=123
  33. index=1

  34. n[1]=45
  35. index=2

  36. n[2]=6789
  37. index=3
複製代碼

TOP

返回列表