C++中substr的用法

C++中substr函数的用法

 1 #include<string> 
 2 #include<iostream> 
 3 using namespace std;
 4 
 5 void main() 
 6 { 
 7 string s("12345asdf"); 
 8 string a=s.substr(0,5);
 9 cout<<a<<endl;
10 }       

上述代码获得字符串s中 从第0位开始的长度为5的字符串.默认时的长度为从开始位置到尾

输出结果为:

12345

原文地址:https://www.cnblogs.com/cynthia-dcg/p/6182514.html