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