当前位置: 首页 > news >正文

如何建立网站服务器网络测试

如何建立网站服务器,网络测试,做汽配网站,公司的网页设计目录 1.string 介绍 2. 初始化 3.输入 4.修改string对象 5.substr截取字符串 6.插入 7.删除 8.替换 9.查找 10.其它操作 1.string 介绍 string是一种字符串类,可以不通过定义字符数组来存储字符串,方便对字符串的一系列操作,使用时…

目录

1.string 介绍

2. 初始化

3.输入

4.修改string对象

5.substr截取字符串

6.插入

7.删除

8.替换

9.查找

10.其它操作

1.string 介绍

string是一种字符串类,可以不通过定义字符数组来存储字符串,方便对字符串的一系列操作,使用时要加上头文件 #include<string>

2. 初始化

(1)常量字符串构造

string str("Hello");

(2)拷贝构造

string str("Hello");
string s(str);

(3)拷贝构造的第二种方式

string str("Hello");
string s = str;

(4)string(size_type n,char c) :创建一个包含 n 个c的 string 对象

string str(5,'a');cout<<str;  //输出aaaaa

(5)部分拷贝构造

string str("hello");
string str2(str,2,3);  //下标2开始的3个字符cout<<str2;  //输出llo

3.输入

string的输入方式不止一种,每一种都有细微差别

(1)cin 键盘输入,会跳过开头的空白,直到遇到下一个空白为止

string str;cin>>str;  //输出abcd efg cout<<str;  //输出abcd 

(2)getline(cin,str) 读取一整行

string str;getline(cin,str);  //输出 abcd efg cout<<str;  //输出 abcd efg

4.修改string对象

(1)通过'+'拼接两个对象

string s1("hello");
string s2("world");
string str=s1+s2;cout<<str;  //输出helloworld

(2)通过append()在末尾添加

string str("hello");
str.append("world");cout<<str;  //输出helloworld

(3)通过push_back()在末尾添加一个字符

string str("hello");
str.push_back('a');cout<<str;  //输出helloa

5.substr截取字符串

 (1)substr(pos,n) 返回从pos下标开始的n个字符,pos默认为下标0;n默认为s.size()-pos

string str("hello");
string str2=str.substr(2,3);cout<<str2;  //输出llo

(2)substr(pos)

string str("hello");
string str2=str.substr(2);cout<<str2;  //输出llo 

6.插入

(1)迭代器位置插入单个字符

string str("hello");
str.insert(str.begin(),'a');cout<<str;  //输出ahello

(2)迭代器位置插入多个字符

string str("hello");
str.insert(str.begin(),3,'a');  //插入3个acout<<str;  //输出aaahello

(3)在下标index前插入n个字符

string str("hello");
str.insert(2,3,'a');cout<<str;  //输出heaaallo 

(4)下标index前插入一个常量字符串或者string对象

string str("hello");
string s("abab");
str.insert(2,s);  //下标2处插入scout<<str;  //输出heababllo 

(5)下标index前插入str中的从某一下标开始的n个字符

string str("hello");
string s("abab");
str.insert(2,s,0,2);  //下标2处插入s下标0开始的两个字符 cout<<str;  //输出heabllo

7.删除

(1)erase()删除全部

string str("hello");str.erase();  //清空 cout<<str;  //输出空

(2)erase(pos,n) 删除下标pos开始的n个字符

string str("hello");str.erase(2,2);  //下标2开始的两个字符 cout<<str;  //输出heo 

(3)erase(迭代器)

string str("hello");str.erase(str.begin());  //删除开头一个字符 cout<<str;  //输出ello 

8.替换

(1)replace(pos,n,s)从下标pos开始删除n个字符,删除后在下标pos处插入s

string str("hello");
string s("aaa");str.replace(2,2,s);  //从下标2开始删除2个字符,删除后在下标2处插入scout<<str;  //输出 heaaao

(2)replace(pos,n,s,a,b)从下标pos开始删除n个字符,删除后在下标pos处插入s中下标a开始的b个字符

string str("hello");
string s("aaa");str.replace(2,2,s,2,1);  从下标2开始删除2个字符,删除后在下标2处插入s的下标2开始的1个字符 cout<<str;  //输出 heao

9.查找

(1)find(s)返回s字符第一次出现的下标

string str("hello");cout<<str.find("ll");  //输出2

(2)find(s,pos)从字符串的 pos 位置开始查找s,返回s字符第一次出现的下标

string str("hello");cout<<str.find('l',3);  //输出3

(3)rfind() 与find()类似,不过是从后往前找

string str("hello");cout<<str.rfind('l');  //输出3

(4)string.find_first_of() 在字符串中从指定位置开始向后(默认为索引 0 处)查找参数中任何一个字符首次出现的位置

string str("hello world people");cout<<str.find_first_of("woooll");  //输出2

(5)find_last_of() 方法在字符串中查找参数中任何一个字符最后一次出现的位置(即从后往前找第一个)

string str("hello world people");cout<<str.find_last_of("woooll");  //输出16

(6)string.find_first_not_of() 在字符串中查找第一个不包含在参数中的字符

string str("hello world people");cout<<str.find_first_not_of("hwoooll");  //输出1

(7)find_last_not_of() 在字符串中查找最后一个不包含在参数中的字符

string str("hello world people");cout<<str.find_last_not_of("hwoooll");  //输出17

10.其它操作

(1)empty()判空 ,若字符串为空,则返回真,否则返回假

string str("hello world people");cout<<str.empty();  //输出0

(2)swap 函数交换两个字符串

string s1("hello");
string s2("world");
s1.swap(s2);cout<<s1<<endl;  //输出world
cout<<s2<<endl;  //输出hello 

http://www.mmbaike.com/news/31194.html

相关文章:

  • 如何注销网站备案南京广告宣传公司seo
  • 郑州企业网站排名优化班级优化大师使用心得
  • 软件项目管理流程神马seo服务
  • 租赁合同模板廊坊百度提升优化
  • 福州cms模板建站免费精准客源
  • 网站内页百度提交口百度客服在线咨询人工服务
  • icp备案网站接入信息ip地址段企业网络搭建
  • 北京 手机网站建设江苏seo排名
  • ip钓鱼网站在线生成住房和城乡建设部官网
  • 京东网站开发技术做电商需要什么条件
  • 怎么做二维码网站网络推广公司加盟
  • 淘宝wordpress cms主题优化步骤
  • 网站搜索排名优化怎么做关键词代发排名
  • 重庆公司团建推荐属于seo网站优化
  • 深圳营销型网站建设服务价格网上国网app
  • 什么网站可以接单做设计衡阳网站优化公司
  • 网站开发 创造收益商品推广与营销的方式
  • 新公司怎样做网站在四川眉山百度竞价推广什么意思
  • 9255tv直播nba5网站优化什么意思
  • 做地方门户网站的排名企业网站首页
  • 盐城哪家专业做网站舆情网站直接打开怎么弄
  • 凡科建站怎么保存网站全网推广引流黑科技
  • 北京b2c网站开发百度认证
  • 网站建设的技术方案模板下载广州网站营销seo
  • 做网站 空间还是服务器全渠道营销
  • 有优惠券网站 怎么做代理优化营商环境条例
  • 低价网站制作顺德百度合作平台
  • 地球人--一家只做信誉的网站网站优化网站优化
  • 中国建设银行网站 个人软文推广例子
  • 合肥网站开发 合肥网站优化福州短视频seo网红