【小摘抄】关于C++11下 string各类用法(持续更新)

http://blog.csdn.net/autocyz/article/details/42391155

提供了最简单的详解

下列对本人近期开发中的一些心得体会进行摘抄

1.string按照字符进行截取

示例代码:

string teststring = "#12313#kajlkfdsa";//通讯消息示例,结合string的内置函数特点,特意只取两个信息在一起
 int tag[2];
 tag[0] = teststring.find("#");//找到第一个#的位置
 tag[1] = teststring.rfind("#");//找到最后一个#,此处刚好是第二个#的位置
 string a,a2;
 a = teststring.substr(tag[0]+1,tag[1]-1);
 a2 = teststring.substr(tag[1]+1, teststring.size());
 cout << a << endl;
 cout << a2;

输出结果:

还有想说:find和rfind都是搜索失败返回-1

原文地址:https://www.cnblogs.com/sbhyc/p/8470356.html