C++STL常用操作之总篇

C++STL常用操作之总篇

1.STL简介:

STL(Standard Template Library),标准模板库。

STL的代码主要分为algorithm(算法)、container(容器)、iterator(迭代器);另外还有仿函数、适配器、空间配置器。

在STL中,vector封装了数组,string封装了字符串,map、set封装了平衡二叉树,stack封装了栈,queue封装了队列,lower_bound和upper_bound封装了二分查找……

我们在编程过程中,经常会用到相关的内容,而自己coding起来又非常的费时费力,使用前辈们已经做好的STL库会方便很多。

优点:
  • STL 是 C++的一部分,因此不用额外安装什么,它被内建在你的编译器之内。
  • STL 的一个重要特性是将数据和操作分离。数据由容器类别加以管理,操作则由可定制的算法定义。迭代器在两者之间充当“粘合剂”,以使算法可以和容器交互运作
  • 程序员可以不用思考 STL 具体的实现过程,只要能够熟练使用 STL 就 OK 了。这样他们就可以把精力放在程序开发的别的方面。
  • STL 具有高可重用性,高性能,高移植性,跨平台的优点。
    • 高可重用性:STL 中几乎所有的代码都采用了模板类和模版函数的方式实现,这相比于传统的由函数和类组成的库来说提供了更好的代码重用机会。
    • 高性能:如 map 可以高效地从十万条记录里面查找出指定的记录,因为 map 是采用红黑树的变体实现的。
    • 高移植性:如在项目 A 上用 STL 编写的模块,可以直接移植到项目 B 上。

2.常用内容:

vector:https://blog.csdn.net/qq_45985728/article/details/112598270

string:https://blog.csdn.net/qq_45985728/article/details/112601755

stack:https://blog.csdn.net/qq_45985728/article/details/112616443

queue:https://blog.csdn.net/qq_45985728/article/details/112624175

pair:https://blog.csdn.net/qq_45985728/article/details/112666687

map:https://blog.csdn.net/qq_45985728/article/details/112687378

multimap:https://blog.csdn.net/qq_45985728/article/details/112789885

set:https://blog.csdn.net/qq_45985728/article/details/112791689

multiset:https://blog.csdn.net/qq_45985728/article/details/112794484

priority_queue:https://blog.csdn.net/qq_45985728/article/details/113044949

sort:https://blog.csdn.net/qq_45985728/article/details/113048880

lower_bound、upper_bound:https://blog.csdn.net/qq_45985728/article/details/113054130

unordered_map:https://blog.csdn.net/qq_45985728/article/details/113663410

猜你喜欢

转载自blog.csdn.net/qq_45985728/article/details/113056198