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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-03-02
猜你喜欢
  • 2022-01-27
  • 2021-11-10
相关资源
相似解决方案