当前位置: 首页 > 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.yidumall.com/news/83406.html

相关文章:

  • 做家具定制的设计网站天津网站优化软件
  • 无锡做网站首选众诺吉林seo管理平台
  • 自己做的网站被篡改怎么办营销策略有哪些方法
  • wordpress个人网站主题北京seo助理
  • 东莞中小企业网站制作免费b站推广入口
  • 钉钉如何做自己的网站如何自己开发网站
  • 网站原型怎么做广州网站制作公司
  • 中企动力有多少家分公司seo是什么专业
  • 怎么制作爆米花教程潍坊自动seo
  • 长春做网站的北京网站优化校学费
  • 辽宁工程建设信息网诚信库seo个人优化方案案例
  • 网站怎么优化关键词软件开发定制
  • 网站新手引导怎么做如何建立企业网站
  • 常州网站建设哪家便宜公司网站建设费用多少
  • 德阳网站制作推广方式都有哪些
  • 深圳住建网国外seo比较好的博客网站
  • 网站建设包括哪些方面优化设计五年级下册语文答案
  • 网站备案网站建设方案人工智能教育培训机构排名
  • 刷网站排名怎么刷百度网络营销中心app
  • 如何建立微网站北京优化seo排名
  • 电商设计就是网站设计吗培训网站模板
  • 一般做网站销售提成今日热点新闻素材
  • 个人建设网站要钱吗seo软文推广工具
  • 大连网站建设 领超最好最新时事热点
  • 做水果的网站网络营销是网上销售吗
  • 滑县住房和城乡建设局网站哈尔滨网站建设
  • 网店转让平台排行榜太原百度搜索排名优化
  • 企业网站备案费用海外推广是做什么的
  • 做网站的系统功能需求百度官方电话
  • 怎么看一个网站做的好不好长沙全网覆盖的网络推广