分割字符串
来源:互联网 发布:网络不稳定不能玩dnf 编辑:程序博客网 时间:2024/06/15 20:49
//string头文件中find函数就是在主字符串中查找子字符串的索引。
//从字符串s 下标5开始,查找字符串b ,返回b 在s 中的下标
//position=s.find("b",5);
//cout<<"s.find(b,5) is : "<<position<<endl;
//标准库的string有一个substr函数用来截取子字符串。一般使用时传入两个参数,第一个是开始的坐标(第一个字符是0),第二个是截取的长度。
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<"请输入要截取的字符串:"<<endl;
string str;
cin>>str;
cout<<"请输入截取点的标志字符"<<endl;
char c;
cin>>c;
int a=0;
int b=0;
while(b = str.find(c,a))
{
if (b<1)
{
break;
}
string temp = str.substr(a,b-a);
cout<<temp<<endl;
a = b+1;
b = 0;
}
return 0;
}
阅读全文
0 0
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 分割字符串
- 分割字符串
- 字符串分割
- 分割字符串
- 字符串分割
- 字符串分割
- 分割字符串
- 秒懂!四步16点高效搞定高性能web服务器nginx
- C++多态 & 虚函数 & 虚析构 & 覆盖 & 虚表
- cento6.X安装zabbix3.4
- 从给定的N个数中得到满足K数的所有数字,时间复杂度O(n)
- 数据库设计的三大范式
- 分割字符串
- String, StringBuffer,StringBuilder的区别
- Java线程学习笔记(一)
- Tp3.2小程序商城源码加后台管理
- pod报错:Automatically assigning platform `ios` with version `10.0` on target `CloudLive` because no pl
- 上传项目到jcenter
- CentOS7 下 Zabbix3.4 源码安装
- linephone 各版本sdk和apk 下载地址
- 最大子序列(java)