substr( )函数

------------恢复内容开始------------

#include <iostream>  
#include <string.h>  
using namespace std;  
 
int main()  
{  
    string s="abcdefg";  
    string s1=s.substr(2,6);//s1为字符串s起始位置为2,长度为6的一段字符串,注意s的位置是从0开始的,即‘a'的位置为0  
    cout<<"s1="<<s1<<endl;  
 
    string s2=s.substr(5);//s2为字符串s起始位置为5,一直到s的末尾的一段字符串  
    cout<<"s2="<<s2<<endl;  
    return 0;  

原文链接:https://blog.csdn.net/qq_41333844/article/details/79845807

------------恢复内容结束------------

猜你喜欢

转载自www.cnblogs.com/minqqq/p/12337537.html