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

做软装素材从哪些网站找什么是搜索引擎推广

做软装素材从哪些网站找,什么是搜索引擎推广,潮汕网站建设,丹灶网站建设string基本概念 string是C风格的字符串,本质上是一个类。 string 和 char* 的区别 char* 是一个指针; string是一个类,内部封装了 char* ,用来管理字符串,是一个 char* 型的容器。 特点 string内部封装了很多成员…

string基本概念

string是C++风格的字符串,本质上是一个类。

string 和 char* 的区别

char* 是一个指针;

string是一个类,内部封装了 char* ,用来管理字符串,是一个 char* 型的容器。

特点

string内部封装了很多成员函数

例如:查找find、拷贝copy、删除delete、替换replace、插入insert

string管理 char* 分配的内存,不用担心复制越界和取值越界等,由类内部负责。

string的构造函数

#include <iostream>
#include <Windows.h>
#include <string>
#include <vector>
#include <algorithm> // 使用STL提供的遍历算法,遍历vector容器using namespace std;void test()
{// 默认构造string s1 = "Hello World";cout << "s1 = " << s1 << endl;// 第二种构造函数const char* str = "Hello World";string s2(str);cout << "s2 = " << s2 << endl;// 第三种构造函数string s3(s2);cout << "s3 = " << s3 << endl;// 第四种构造函数string s4(10, 'A');cout << "s4 = " << s4 << endl;
}int main(void)
{test();system("pause");return 0;
}

运行截图:

 string赋值操作

#include <iostream>
#include <Windows.h>
#include <string>using namespace std;void test()
{// 第一种赋值方式string s1 = "Hello World";cout << "s1 = " << s1 << endl;// 第二种赋值方式string s2;s2 = s1;cout << "s2 = " << s2 << endl;// 第三种赋值方式string s3;s3 = 'A';cout << "s3 = " << s3 << endl;// 第四种赋值方式string s4;s4.assign("Hello C++");cout << "s4 = " << s4 << endl;//第五种赋值方式string s5;s5.assign("Hello C++", 5);cout << "s5 = " << s5 <<endl;// 第六种赋值方式string s6;s6.assign(s5);cout << "s6 = " << s6 <<endl;// 第七种赋值方式string s7;s7.assign(10, 'W');cout << "s7 = " << s7 << endl;}int main(void)
{test();system("pause");return 0;
}

运行截图:

string字符串拼接

#include <iostream>
#include <Windows.h>
#include <string>using namespace std;void test()
{// 第一种字符串拼接方式string str1 = "Hello";str1 += " C++";cout << str1 << endl;// 第二种字符串拼接方式str1 += '!';cout << str1 << endl;// 第三种字符串拼接方式string str3 = " Good morning";str1 += str3;cout << str1 << endl;// 第四种字符串拼接方式string str4 = "I";str4.append(" Love ");cout << str4 << endl;// 第五种字符串拼接方式string str5 = str4;str5.append("C++ and Java", 3);cout << str5 << endl;// 第六种字符串拼接方式string str6 = "你好:";str6.append(str1);cout << str6 << endl;// 第七种字符串拼接方式string str7;str7.append(str1, 0, 9);cout << str7 << endl;}int main(void)
{test();system("pause");return 0;
}

运行截图:

 

string字符串查找和替换

#include <iostream>
#include <Windows.h>
#include <string>using namespace std;// 字符串查找
void test()
{string s1 = "Hello World";int pos = s1.find("Hello");if (pos == -1){cout << "未找到字符串" << endl;}else{cout << "pos = " << pos << endl; // pos = 0}
}// 字符串替换
void test02()
{string str = "Hello World";str.replace(6, 5, "C++");cout << str << endl;
}int main(void)
{test();test02();system("pause");return 0;
}

运行截图:

 

string字符串比较

#include <iostream>
#include <Windows.h>
#include <string>using namespace std;void test()
{string s1 = "Hello World";string s2 = "Hello";if (s1.compare(s2) == 0){cout << "字符串相等" << endl;}else{cout << "字符串不等" << endl;}
}int main(void)
{test();system("pause");return 0;
}

运行截图:

 

string字符串存取

#include <iostream>
#include <Windows.h>
#include <string>using namespace std;void test()
{string s = "Hello World";// 1、通过[]访问单个字符for (int i = 0; i < s.size(); i++){cout << s[i] << "  ";}cout << endl;// 2、通过at访问单个字符for (int i = 0; i < s.size(); i++){cout << s.at(i) << "  ";}cout << endl;}int main(void)
{test();system("pause");return 0;
}

运行截图:

 

string子串获取

#include <iostream>
#include <Windows.h>
#include <string>using namespace std;void test()
{string s1 = "Hello World";string s2 = s1.substr(6, 5);cout << s2 << endl; // 输出World
}int main(void)
{test();system("pause");return 0;
}

运行截图:

http://www.hkea.cn/news/697816/

相关文章:

  • 网站建设案例资料今天的新闻内容
  • 台州专业网站建设方案seo软文代写
  • 个人网站 百度推广全球搜索大全
  • 网站消息推送5118素材网站
  • 天津 响应式网站设计企业网站模板免费
  • 网站用花生壳nas做存储百度seo发包工具
  • wordpress cache深圳纯手工seo
  • 怎样找到正规代加工网站百度地图3d实景地图
  • 潍坊网站建设公司网站搭建免费
  • 惠州做网站好的公司下载百度语音导航地图安装
  • 春节网站怎么做小说排行榜百度搜索风云榜
  • 商城服务是什么软件seo是指什么岗位
  • 无锡网站建设有限公司网站快速收录的方法
  • 网站建设通报推广网站多少钱
  • 网络推广公司成都seo排名优化教程
  • 一台手机登录微信网页版西安优化外
  • 如何做旅游攻略网站长沙seo优化推荐
  • 长春火车站电话咨询电话快排seo
  • 龙城建设网站公司网站内容优化方法
  • 南通网站建设搭建网站卖链接
  • 驻马店市做网站seo臻系统
  • 找公司做网站怎么图片都要自己找百度推广官网电话
  • 网站小样用什么做seo外链平台热狗
  • 建站点的步骤sem是什么
  • 深圳专业做网站的衡水网站优化推广
  • 徐汇科技网站建设2345中国最好的网址站
  • 邢台论坛吧百度seo收录软件
  • 做国外服务器网站吗怎么让百度搜索靠前
  • 做动态图网站有哪些自建站怎么推广
  • web网站开发课程设计报告seo技术培训沈阳