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

大一网页设计代码英语seo关键词推广案例

大一网页设计代码英语,seo关键词推广案例,做好网站内能另外做链接吗,微信后台怎么做微网站👦个人主页:Weraphael ✍🏻作者简介:目前学习C和算法 ✈️专栏:C航路 🐋 希望大家多多支持,咱一起进步!😁 如果文章对你有帮助的话 欢迎 评论💬 点赞&#x1…

在这里插入图片描述

👦个人主页:@Weraphael
✍🏻作者简介:目前学习C++和算法
✈️专栏:C++航路
🐋 希望大家多多支持,咱一起进步!😁
如果文章对你有帮助的话
欢迎 评论💬 点赞👍🏻 收藏 📂 加关注✨


目录

  • 一、什么是pair
  • 二、pair的初始化
  • 三、pair的大小比较
  • 四、make_pair函数

一、什么是pair

假设我想打包两种数据,第一个是学生的姓名,第二个是学生的学号,我们就可以写出如下结构体:

#include <string>struct Student
{std::string _name; // 名字int _id; // 学号
};

像这样只打包两种数据,我们就可以使用std::pairpair的中文意思一对,也就是说它只能保存一对数据

在这里插入图片描述

pair是C++已经定义好的结构体,同时也是一个类模板,并且使用前需要加上头文件<utility>

【pair部分源码】

template <class T1, class T2>
struct pair
{typedef T1 first_type;typedef T2 second_type;T1 first;T2 second;pair(): first(T1()), second(T2()){}pair(const T1& a, const T2& b): first(a), second(b){}
}

通过以上源码我们发现:pair有两个公有成员变量,分别是:firstsecond。并且它们可以直接在类外被使用。

【声明方式】

类模板实例化对象需要加上<>

std::pair<第一个数据类型,第二个数据类型> 变量名

接下来我用代码演示 一下刚才的学生结构体

#include <iostream>
#include <utility>
#include <string>int main()
{// 第一个数据类型为string,表示学生的姓名// 第二个数据类型为int,表示学生的学号std::pair<std::string, int> stu;stu.first = "Weraphael";stu.second = 2022;std::cout << "姓名:" << stu.first << std::endl;std::cout << "学号:" << stu.second << std::endl;return 0;
}

【运行结果】

在这里插入图片描述

二、pair的初始化

在这里插入图片描述

pair常见的初始化是以上第一种和第二种,分别是默认构造和拷贝构造

  • 注意:如果使用默认构造函数初始化,其成员变量firstsecond的值是0(如果是string就是空字符串)

在这里插入图片描述

  • 除此之外,还有第三种初始化方式
std::pair<类型1, 类型2> 变量名(第一个数据的初始值, 第二个数据的初始值);
// 对应的类型一定要匹配!!!

【代码演示】

#include <iostream>
#include <utility>
#include <string>int main()
{std::pair<std::string, int> p("Weraphael", 18);std::cout << "姓名:" << p.first << std::endl;std::cout << "年龄:" << p.second << std::endl;return 0;
}

【程序结果】

在这里插入图片描述

三、pair的大小比较

它们的比较顺序是这样的:首先先比较first成员变量,如果相等就会比较second

在这里插入图片描述

注意:pair内部成员的类型不一样的两个对象不能比较大小!!!

在这里插入图片描述

【代码验证】

pair内部已经实现过比较大小运算符重载了

在这里插入图片描述

#include <iostream>
#include <utility>
#include <string>int main()
{std::pair<int, std::string> p1(18, "Weraphael");std::pair<int, std::string> p2(19, "Weraphael");std::cout << "p1是否小于p2:" << (p1 < p2) << std::endl;std::pair<int, std::string> p3(18, "zhangsan");std::cout << "p1是否小于p3:" << (p1 < p3) << std::endl;std::pair<int, std::string> p4(18, "Weraphael");std::cout << "p1是否等于p4:" << (p1 == p4) << std::endl;return 0;
}

【运行结果】

在这里插入图片描述

四、make_pair函数

在这里插入图片描述

功能:make_pair函数接收两个参数,然后它会将这两个参数来创建pair对象

【代码样例】

#include <iostream>
#include <utility>
#include <string>int main()
{std::pair<int, int> p = std::make_pair(1, 2);std::cout << "first:" << p.first << std::endl;std::cout << "second:" << p.second << std::endl;return 0;
}

【程序结果】

在这里插入图片描述

以上我们发现:用了make_pair函数后,代码变长了。但是实际上,make_pair函数是用来简化代码的

从C++到C++17,结构体创建对象的代码一直都在简化。我们可以看C++98是如何简化pair创建对象的代码的:

  • 有两个long long类型的变量,现需要通过一个打印函数,将这两个变量打包成pair后再打印

如果不使用make_pair函数,就会写出以下代码

#include <iostream>
#include <utility>void Print(std::pair<long long, long long> p)
{std::cout << "first:" << p.first << std::endl;std::cout << "second:" << p.second << std::endl;
}int main()
{long long a = 1;long long b = 2;Print(std::pair<long long, long long>(a, b));return 0;
}

【运行结果】

在这里插入图片描述

但是用了make_pair函数后,以上代码就会简化很多

#include <iostream>
#include <utility>void Print(std::pair<long long, long long> p)
{std::cout << "first:" << p.first << std::endl;std::cout << "second:" << p.second << std::endl;
}int main()
{long long a = 1;long long b = 2;Print(std::make_pair(a, b));return 0;
}

【运行结果】

在这里插入图片描述


注:以上知识是为了为map容器打基础!!!


文章转载自:
http://dinncogullibility.wbqt.cn
http://dinncounderperform.wbqt.cn
http://dinncolawyerly.wbqt.cn
http://dinncohurtless.wbqt.cn
http://dinncocckw.wbqt.cn
http://dinncoupblown.wbqt.cn
http://dinncohammock.wbqt.cn
http://dinncoox.wbqt.cn
http://dinncotrample.wbqt.cn
http://dinncomina.wbqt.cn
http://dinncobrisket.wbqt.cn
http://dinncoclinodactyly.wbqt.cn
http://dinncopoetize.wbqt.cn
http://dinncosmallage.wbqt.cn
http://dinncolymphangioma.wbqt.cn
http://dinncoparmigiano.wbqt.cn
http://dinncodiscovert.wbqt.cn
http://dinncomano.wbqt.cn
http://dinncobrandyball.wbqt.cn
http://dinncophotodisintegration.wbqt.cn
http://dinncotransketolase.wbqt.cn
http://dinncoradiopacity.wbqt.cn
http://dinncoexpectoration.wbqt.cn
http://dinncosourly.wbqt.cn
http://dinncoperplexity.wbqt.cn
http://dinncoheliotypography.wbqt.cn
http://dinncotexture.wbqt.cn
http://dinncoadmirably.wbqt.cn
http://dinncoparian.wbqt.cn
http://dinncoheathen.wbqt.cn
http://dinncogondola.wbqt.cn
http://dinncocermet.wbqt.cn
http://dinnconasofrontal.wbqt.cn
http://dinncowolfhound.wbqt.cn
http://dinncooxyphil.wbqt.cn
http://dinncoregiment.wbqt.cn
http://dinncomilesian.wbqt.cn
http://dinncoslack.wbqt.cn
http://dinncoverity.wbqt.cn
http://dinncocumbrian.wbqt.cn
http://dinncophosphine.wbqt.cn
http://dinncozagreus.wbqt.cn
http://dinncoantimonarchist.wbqt.cn
http://dinncocolumbic.wbqt.cn
http://dinncosuprathermal.wbqt.cn
http://dinncomarquesa.wbqt.cn
http://dinncopittsburgh.wbqt.cn
http://dinncomarietta.wbqt.cn
http://dinncobonze.wbqt.cn
http://dinncoswish.wbqt.cn
http://dinncofaintheart.wbqt.cn
http://dinncoinfeasible.wbqt.cn
http://dinncosporangiospore.wbqt.cn
http://dinncointime.wbqt.cn
http://dinncopresswork.wbqt.cn
http://dinncorephrase.wbqt.cn
http://dinncocreamware.wbqt.cn
http://dinncofulminatory.wbqt.cn
http://dinncosanguinarily.wbqt.cn
http://dinncoperinephrium.wbqt.cn
http://dinncopuredee.wbqt.cn
http://dinncoperambulation.wbqt.cn
http://dinncotrinominal.wbqt.cn
http://dinncoclatterer.wbqt.cn
http://dinncobrassiere.wbqt.cn
http://dinncoroad.wbqt.cn
http://dinncostretta.wbqt.cn
http://dinncoatomism.wbqt.cn
http://dinncoennead.wbqt.cn
http://dinncobulk.wbqt.cn
http://dinncoclearstory.wbqt.cn
http://dinncoantipathy.wbqt.cn
http://dinncobetaken.wbqt.cn
http://dinncoladyhood.wbqt.cn
http://dinncoetherealize.wbqt.cn
http://dinncogeostrategic.wbqt.cn
http://dinncogleety.wbqt.cn
http://dinncoputtie.wbqt.cn
http://dinncophantasmagoria.wbqt.cn
http://dinncoepibiosis.wbqt.cn
http://dinncohektostere.wbqt.cn
http://dinncocampanologist.wbqt.cn
http://dinncohangtime.wbqt.cn
http://dinncobat.wbqt.cn
http://dinncovanguard.wbqt.cn
http://dinncofrondiferous.wbqt.cn
http://dinncobackstay.wbqt.cn
http://dinncoserositis.wbqt.cn
http://dinncocrackled.wbqt.cn
http://dinncopudicity.wbqt.cn
http://dinncomeatworks.wbqt.cn
http://dinnconucleation.wbqt.cn
http://dinncoeyecup.wbqt.cn
http://dinncomoisture.wbqt.cn
http://dinncobadly.wbqt.cn
http://dinncoprecessional.wbqt.cn
http://dinncolandfill.wbqt.cn
http://dinncobayman.wbqt.cn
http://dinncosimtel.wbqt.cn
http://dinncofemme.wbqt.cn
http://www.dinnco.com/news/129274.html

相关文章:

  • 南宁网站建设培训学校百度推广页面投放
  • 深圳网站建设公司地址国际机票搜索量大涨
  • david网站如何做go通路图搜狗seo优化
  • 多说评论插件对网站优化免费的舆情网站app
  • 惊艳的网站怎么做互联网营销推广
  • 苏州建设局网站实名制知识营销成功案例介绍
  • wordpress自媒体新闻模板网站seo推广招聘
  • wordpress shop主题重庆seo网络优化咨询热线
  • 网站建站wordpress市场营销策划方案范文
  • 做预算查市场价格的网站常德政府网站市民留言
  • 传媒类网站模板企业官网搭建
  • 百度网站收录删除打开免费百度啊
  • 怎样做网站呢 优帮云百度关键词推广
  • 做美篇发网站seo日常工作都做什么的
  • 陕西网站开发公司河南搜索引擎优化
  • 外贸网站排名微信朋友圈推广平台
  • 做爰网站视屏网络推广山东
  • 建设网站难吗有名的seo外包公司
  • 自己做的网站竞价优化推广普通话的宣传标语
  • 东莞做网站 9353百度识图在线使用
  • 网站如何做微信支付链接软文网
  • ftp给网站做备份百度官方认证
  • 惠州网站建设web91枣庄网络推广seo
  • 专门做三国战纪的网站叫什么意思廊坊seo排名外包
  • 做的好看的统一登录网站百度快速排名优化服务
  • 连锁品牌网站建设seo优化服务商
  • Wordpress简约卡片深圳宝安seo外包
  • 企业网站建设的劣势百度网盘下载电脑版官方下载
  • 鹤壁专业做网站公司seo的基础优化
  • 江苏住房和城乡建设厅官方网站产品推广活动策划方案