![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
字符串
一击必杀心得
这个作者很懒,什么都没留下…
展开
-
C++删除string最后一个字符的几种方法
#include<string>using namespace std;int main(){ string str; str = "123456"; cout << str << endl; //方法一:使用substr() str = str.substr(0, str.length() - 1);...转载 2019-07-09 20:29:06 · 9798 阅读 · 1 评论 -
截取字符串
标准库的string有一个substr函数用来截取子字符串。一般使用时传入两个参数,第一个是开始的坐标(第一个字符是0),第二个是截取的长度#include<bits/stdc++.h>using namespace std;int main(){string s=“123456”;string first(s.substr(2,3));cout<<first...原创 2019-07-09 20:59:42 · 110 阅读 · 0 评论 -
截取字符串
用途:一种构造string的方法形式:s.substr(pos, n)解释:返回一个string,包含s中从pos开始的n个字符的拷贝(pos的默认值是0,n的默认值是s.size() - pos,即不加参数会默认拷贝整个s)补充:若pos的值超过了string的大小,则substr函数会抛出一个out_of_range异常;若pos+n的值超过了string的大小,则sub...转载 2019-07-11 19:22:34 · 142 阅读 · 0 评论