2026/4/6 8:03:27
网站建设
项目流程
江门移动网站建设公司,企业网站制作套餐,wordpress提示框插件,游戏开发需要多少钱#xff0c;STL简介1.1 什么是STL#xff1f;STL的概念#xff1a;STL#xff08;Standard Template Library#xff09;是C标准库的核心组成部分#xff0c;提供了一套通用的模板类和函数#xff0c;用于实现常见的数据结构和算法。1.2 STL的六大组件STL的六大组件是它…STL简介1.1 什么是STLSTL的概念STLStandard Template Library是C标准库的核心组成部分提供了一套通用的模板类和函数用于实现常见的数据结构和算法。1.2 STL的六大组件STL的六大组件是它的核心我们在学习STL的时候也是围绕着这六大组件来进行学习下面看看六大组件都有哪些在这里插入图片描述1.3 如何学习STLSTL提供了一套通用的模板和函数用于实现常见的数据结构那么这些函数和数据结构我们首先要学会使用其实就是了解一下这些数据结构的底层是如何实现的。 所以学习STL的步骤就是1.学会使用 2.了解底层 后面的STL学习都会按照这两个步骤来学习声明二第一个STL容器—string2.1 string的4个默认构造的使用函数名称功能说明string()构造空的string类对象即空字符串重点string(const char* s)用C风格字符串C-string构造string类对象重点string(size_t n, char c)构造包含n个字符c的string类对象string(const string s)通过拷贝另一个string类对象构造新对象重点我们先来看看库里面的一些函数重载在这里插入图片描述在这里插入图片描述代码语言javascriptAI代码解释void TestString1() { string s1;//创建一个空字符串对象 string s2(hello world);//构造 string s3(s2);//拷贝构造 cout s3 endl; string s4(s2, 1, 8);//相当于memcopy //string s4(s1, 1, 60); cout s4 endl; string s6(s2, 1);//不写长度那就从1开始拷贝 直到s2被拷贝完 cout s6 endl; const char* str1 hello word; string s7(str1,5); //使用char* 的字符串构造 cout s7 endl; string s8(100, *);//将s8初始化成100个* cout s8 endl; //赋值运算符重载 s1.operator() s1 s2; s1 *******; cout s1 endl; }还有一个析构函数用于释放string内部的资源在模拟实现部分会详细说明。三初识迭代器3.1 使用迭代器遍历string学习一个数据结构就要学会它的遍历因为在使用数据结构的时候我们常常会修改数据结构内部的值如果我们要一一进行修改那么就一定会用到遍历。在学习C语言的时候常见的遍历方式是使用for循环while循环等借助循环来遍历。而C搞了一个新的遍历方式叫迭代器它是所有的主流遍历方式下面我们重点讲解它。www.dongchedi.com/article/7592326493200482841www.dongchedi.com/article/7592329049750995481www.dongchedi.com/article/7592327070701961753www.dongchedi.com/article/7592322906135413273www.dongchedi.com/article/7592308231180026392www.dongchedi.com/article/7592331190716498457www.dongchedi.com/article/7592320610865676825www.dongchedi.com/article/7592326493201007129www.dongchedi.com/article/7592322714795688510www.dongchedi.com/article/7592327392942178841www.dongchedi.com/article/7592319617927283225www.dongchedi.com/article/7592327476282638873www.dongchedi.com/article/7592319094112846360www.dongchedi.com/article/7592326854393152025www.dongchedi.com/article/7592319386741244441www.dongchedi.com/article/7592321316729504281www.dongchedi.com/article/7592319724022039102www.dongchedi.com/article/7592327140348379672www.dongchedi.com/article/7592319412238418457www.dongchedi.com/article/7592319724022137406www.dongchedi.com/article/7592319070578917950www.dongchedi.com/article/7592317677180486168www.dongchedi.com/article/7592331430680953368www.dongchedi.com/article/7592317943112057368www.dongchedi.com/article/7592312482736685593www.dongchedi.com/article/7592326787452011070www.dongchedi.com/article/7592320171805934142www.dongchedi.com/article/7592312175293891097www.dongchedi.com/article/7592326095602221593www.dongchedi.com/article/7592313460353466942www.dongchedi.com/article/7592315921234985497www.dongchedi.com/article/7592318584517493310www.dongchedi.com/article/7592313903104164377www.dongchedi.com/article/7592314981853905432www.dongchedi.com/article/7592327419139654169www.dongchedi.com/article/7592312482736620057www.dongchedi.com/article/7592327392941589017www.dongchedi.com/article/7592313382368297497www.dongchedi.com/article/7592317900531548734www.dongchedi.com/article/7592315372943327769www.dongchedi.com/article/7592311873639432729www.dongchedi.com/article/7592316979160121918www.dongchedi.com/article/7592312719127511577www.dongchedi.com/article/7592316786557616664www.dongchedi.com/article/7592327116290032153www.dongchedi.com/article/7592326416835002904www.dongchedi.com/article/7592313347400270360