C++中substr函数的用法

来源:互联网 发布:淘宝韩国代购真假 编辑:程序博客网 时间:2024/05/18 03:51

C++中substr函数的用法

#include<string>
#include<iostream>
using namespace std;

main()
{
string s("12345asdf");
string a=s.substr(0,5);       //获得字符串s中 从第0位开始的长度为5的字符串//默认时的长度为从开始位置到尾
cout<<a<<endl;
}

输出结果为:

12345