string::substr
string substr (size_t pos = 0, size_t len = npos) const;
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s1 = "i love lyy, lyy like eat mouse";
    string s2 = s1.substr(7, 3); 
    cout << s2 << endl;
    s2 = s1.substr(5);
    cout << s2 << endl;
    try 
    {   
        s2 = s1.substr(50);
    }catch(out_of_range)
    {   
        cout << "out_of_range" << endl;
    }   
    cout << s2 << endl;
    s2 = s1.substr(s1.length());
    cout << s2 << endl;
    return 0;
}
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号