返回列表 發帖

[6/8 作業2] substr() 函式

本帖最後由 tonyh 於 2024-6-8 11:41 編輯

試以 substr() 函式,抓出字串中特定範圍內的字串。
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;  //56789
  9.     cout<<str.substr(2)<<endl;  //23456789
  10.     cout<<str.substr(3,3)<<endl;  //345
  11.     cout<<str.substr(7,1)<<endl;  //7
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;//56789
  9.     cout<<str.substr(2)<<endl;//23456789
  10.     cout<<str.substr(3,3)<<endl;//345
  11.     cout<<str.substr(7,1)<<endl;//7
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;  //56789
  9.     cout<<str.substr(2)<<endl;  //23456789
  10.     cout<<str.substr(3,3)<<endl;  //345
  11.     cout<<str.substr(7,1)<<endl;  //7
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;  //56789
  9.     cout<<str.substr(2)<<endl;  //23456789
  10.     cout<<str.substr(3,3)<<endl;  //345
  11.     cout<<str.substr(7,1)<<endl;  //7
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;  //56789
  9.     cout<<str.substr(2)<<endl;  //23456789
  10.     cout<<str.substr(3,3)<<endl;  //345
  11.     cout<<str.substr(7,1)<<endl;  //7
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     string str="0123456789";
  6.     cout<<str.substr(5)<<endl;  
  7.     cout<<str.substr(2)<<endl;
  8.     cout<<str.substr(3,3)<<endl;
  9.     cout<<str.substr(7,1)<<endl;
  10.     system("pause");     
  11.     return 0;   
  12. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     string str="0123456789";
  6.     cout<<str.substr(5)<<endl;
  7.     cout<<str.substr(2)<<endl;
  8.     cout<<str.substr(3,3)<<endl;
  9.     cout<<str.substr(7,1)<<endl;
  10.     system("pause");
  11.     return 0;
  12. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;
  9.     cout<<str.substr(2)<<endl;
  10.     cout<<str.substr(3, 3)<<endl;
  11.     cout<<str.substr(7, 1)<<endl;
  12.     system("pause");
  13.     return 0;
  14. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<iostream>
  4. #include<cstdlib>
  5. #include<string>
  6. using namespace std;
  7. int main()
  8. {
  9.     string str="0123456789";
  10.     cout<<str.substr(5)<<endl;
  11.     cout<<str.substr(2)<<endl;
  12.     cout<<str.substr(3,3)<<endl;
  13.     cout<<str.substr(7,1)<<endl;
  14.     system("pause");     
  15.     return 0;   
  16. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;
  9.     cout<<str.substr(2)<<endl;
  10.     cout<<str.substr(3,3)<<endl;
  11.     cout<<str.substr(7,1)<<endl;
  12.     system("pause");     
  13.     retur
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;  
  9.     cout<<str.substr(2)<<endl;  
  10.     cout<<str.substr(3,3)<<endl;  
  11.     cout<<str.substr(7,1)<<endl;  
  12.     system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     string str="0123456789";
  6.     cout<<str.substr(5)<<endl;
  7.     cout<<str.substr(2)<<endl;
  8.     cout<<str.substr(3,3)<<endl;
  9.     cout<<str.substr(7,1)<<endl;
  10.     system("pause");     
  11.     return 0;   
  12. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     string str="0123456789";
  8.     cout<<str.substr(5)<<endl;  
  9.     cout<<str.substr(2)<<end
  10.     cout<<str.substr(3,3)<<endl;
  11.     cout<<str.substr(7,1)<<endl;
  12. system("pause");     
  13.     return 0;   
  14. }
複製代碼

TOP

#include<bits/stdc++.h>
using namespace std;

int main()
{
    string str="0123456789";
    cout<<str.substr(5)<<endl;
    cout<<str.substr(2)<<endl;
    cout<<str.substr(3.3)<<endl;
    cout<<str.substr(7.1)<<endl;
   
    return 0;
}

TOP

返回列表