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

设计类网站开发策划书/浅议网络营销论文

设计类网站开发策划书,浅议网络营销论文,wordpress的插件,网站建设公司有1.本质 string是C风格的字符串,本质上是一个类 2.与char*区别 string在内部封装了char*,是char*的容器 3.特点 string内部封装了很多成员方法; string管理char*的内存,不用担心复制越界和取值越界,由类对它负责。…

1.本质

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

2.与char*区别

string在内部封装了char*,是char*的容器

3.特点

string内部封装了很多成员方法;

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

4.构造函数

1.分类

(3是拷贝构造)

2.代码演示

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{//默认构造string s1;//使用一个字符串进行初始化string s2("hello world");cout << s2 << endl;//使用拷贝构造string s3(s2);cout << s3 << endl;//使用n个字符进行初始化string s4(10, 'a');cout << s4 << endl;return 0;
}

3.总结

这些构造函数没有可比性,灵活使用即可

4.赋值

1.函数原型

2.利用等号

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1;s1 = "hello world";cout << s1 << endl;string s2;s2 = s1;cout << s2 << endl;string s3;s3 = 'a';cout << s3 << endl;return 0;
}

3.利用assign内置成员函数

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1;s1.assign("hello C++");cout << s1 << endl;string s2;s2.assign(s1);cout << s2 << endl;string s3;//取s2的前5个s3.assign(s2,5);cout << s3 << endl;string s4;//将十个w组合在一起s4.assign(10, 'w');cout << s4 << endl;return 0;
}

5.字符串拼接

1.功能

实现在字符串末尾拼接字符串

2.函数原型

3.使用+=进行追加

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abc";//追加字符串s1 += "def";cout << s1 << endl;//追加字符s1 += 'g';cout << s1 << endl;string s2 = "奥里给";//追加同类容器s2 += s1;cout << s2 << endl;return 0;
}

4.使用内置成员函数append追加

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "I ";//追加字符串s1.append("love game ");cout << s1 << endl;string s2 = "LOL GTA ";//追加类s1.append(s2);cout << s1 << endl;string s3 = "wcnm";//追加字符串的前两个个字符s1.append("wcnm", 2);//s1.append(s3, 2);cout << s1 << endl;//追加的第二个字符开始后的两个字符(从0开始计算的)s1.append(s3, 2, 2);cout << s1 << endl;return 0;
}

注意:

s1.append(s3, 2);

不能将追加字符串前两个字符的代码写成这样,这样输出的结果是输出类中从第二个开始数知道结尾的字符(注意是从0开始计算的)

(有看不懂的就去看函数原型)

6.查找和替换

1.函数原型

2.查找

1.find

查找字符串第一次出现的位置

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefg";int pos = s1.find("de");cout << pos << endl;return 0;
}

若成功找到,返回她第一次出现的位置(因为索引是从0开始的)

若没有找到返回-1

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefg";int pos = s1.find("df");cout << pos << endl;return 0;
}

2.rfind

与find区别:rfind是从右往左查找,find是从左往右查找

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefgde";int pos = s1.rfind("de");cout << pos << endl;return 0;
}

注意:虽然从右往左查,不过索引顺序还是按照从左往右的顺序,并且仍然是d的位置。

3.替换

作用:将从参数一开始的之后的参数二的这些字符替换成参数三

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefgde";s1.replace(1,3,"1111");cout << s1 << endl;return 0;
}

7.字符串比较

1.比较方式

根据ASCLL码来比较

=返回  0

>返回  1

<返回  -1

2.函数原型

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abc";string s2 = "cbc";if (s1.compare(s2) == 0){cout << "s1 等于 s2" << endl;cout << s1.compare(s2) << endl;}else if (s1.compare(s2) > 0){cout << "s1 大于 s2" << endl;cout << s1.compare(s2) << endl;}else if (s1.compare(s2) < 0){cout << "s1 小于 s2" << endl;cout << s1.compare(s2) << endl;}return 0;
}

注意:与C语言的字符串比较的原理相同

8.字符存取

1.函数原型

2.通过[]访问单个字符

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefg";for (int i = 0; i < size(s1); i++){cout << s1[i] << " ";}cout << endl;return 0;
}

注意:其中size(s1)计算的是s1的长度

3.通过at访问单个字符

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefg";for (int i = 0; i < s1.size(); i++){cout << s1.at(i) << " ";}cout << endl;return 0;
}

4.修改字符串的单个字符

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefg";s1[0] = 'b';s1.at(1) = 'a';cout <<s1<< endl;return 0;
}

9.插入和删除

1.函数原型

2.插入

insert语法:在”第一个参数“个的字符前面插入“第二个参数”。

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "hello";s1.insert(1, "111");cout << s1 << endl;return 0;
}

3.删除

erase语法:从“第一个参数”起,删除“第二个参数”个字符

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "h111ello";s1.erase(1, 3);cout << s1 << endl;return 0;
}

10.子串获取

1.函数原型

2.代码实现

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{string s1 = "abcdefg";string s2 = s1.substr(1, 3);cout << s2 << endl;return 0;
}

3.实用操作

从邮箱地址中获取用户名

#include<stdio.h>
using namespace std;
#include<string>
#include <iostream>int main()
{//从邮箱地址中获取用户名string s1 = "17853400693@163.com";int pos = s1.find("@");string user = s1.substr(0,pos);cout << user << endl;return 0;
}

http://www.whsansanxincailiao.cn/news/32035584.html

相关文章:

  • 网站如何做rss订阅/盘搜搜
  • 中国500强企业排名/seo官网优化
  • 阿里云做网站/武汉本地seo
  • 相亲网站拉人做基金/关键词seo排名
  • 用php怎么做网站/成都网站关键词排名
  • 怎么做家政的网站/网站制作郑州
  • 泊头哪有哪家做网站做的号/快优吧seo优化
  • 郑州做网站排名/搜索引擎营销的主要方式有
  • 青岛做网站皆赴青岛博/陕西seo主管
  • 手机上做网站/千锋教育培训多少钱费用
  • 人大网站的建设/网络赚钱推广
  • 做纸贸易的好网站/竞价账户
  • 浙江电商网站建设销售/徐州百度推广公司
  • 中国最受欢迎的网站/seo用什么工具
  • vuejs 网站开发/免费海报模板网站
  • 对于网站建设提出建议/网站收录提交
  • 可以做文档赚钱的网站/最新的疫情情况
  • adobe做网站的软件/关键词优化一年的收费标准
  • 国外做旅游攻略的网站/seo关键词优化推荐
  • 哪家网站做的好/鄂州seo
  • 新网站如何做流量/网络推广官网首页
  • 公司网站设计与实现的英文文献/青岛网站建设与设计制作
  • 网站建设广告宣传/金华百度seo
  • 织梦怎么做中英文网站/百度下载并安装最新版
  • 网站被劫持/百度竞价推广方案范文
  • 长春市网站建设dbd3/百度号注册官网
  • 制作网站的程序/推广网络营销外包公司
  • jsp做网站框架/不受限制的搜索引擎
  • 公司设计一个网站/seo优化工作
  • 做网站工作/济南百度代理