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

dede网站 异步生成做网站从哪方面入门

dede网站 异步生成,做网站从哪方面入门,旅游网站 功能,进口手表网站【STL容器】序列容器——vector容器一、简介二、头文件三、模板类四、成员函数1、迭代器2、元素访问3、容量4、修改操作五、demo1、容量reserve、capacity、shrink_to_fit2、修改操作pop_back()、push_back3、修改操作insert()4、修改操作emplace()5、修改操作erase()、swap()、… 【STL容器】序列容器——vector容器一、简介二、头文件三、模板类四、成员函数1、迭代器2、元素访问3、容量4、修改操作五、demo1、容量reserve、capacity、shrink_to_fit2、修改操作pop_back()、push_back3、修改操作insert()4、修改操作emplace()5、修改操作erase()、swap()、clear() 、6、emplace_back()和push_back()的区别7、insert()和emplace()一、简介 vector 实现的是一个动态数组即可以进行元素的插入和删除在此过程中vector 会动态调整所占用的内存空间整个过程无需人工干预。 array实现的是一个静态数组。 vector 常被称为向量容器因为该容器擅长在尾部插入或删除元素在常量时间内就可以完成时间复杂度为O(1)而对于在容器头部或者中部插入或删除元素则花费时间要长一些移动元素需要耗费时间时间复杂度为线性阶O(n)。 二、头文件 #includevector三、模板类 templateclass T,class Allocator std::allocatorTclass vector;四、成员函数 1、迭代器 成员函数功能begin()同array容器end()同array容器rbegin()同array容器rend()同array容器cbegin()同array容器cend()同array容器crbegin()同array容器crend()同array容器 2、元素访问 成员函数功能at(n)同array容器operator[]同array容器front()同array容器back()同array容器data()同array容器 3、容量 成员函数功能empty()同array容器size()同array容器max_size()同array容器reserve增加容器的容量。capacity返回当前容量。shrink_to_fit将内存减少到等于当前元素实际所使用的大小。 4、修改操作 成员函数功能clear()移出所有的元素容器大小变为 0。insert()在指定的位置插入一个或多个元素。emplace()在指定的位置直接生成一个元素。erase()移出一个元素或一段元素。push_back()在序列的尾部添加一个元素。emplace_back()在序列尾部生成一个元素。pop_back()移出序列尾部的元素。resize()调整容器的大小。swap()交换两个容器的所有元素。 五、demo 1、容量reserve、capacity、shrink_to_fit //array 容器。 #include iostream #include vector #includestring using namespace std; int main() {vectorstring v{ one,two,three,four,five }; cout v.size() v.size() endl;cout v.capacity() v.capacity() endlendl;v.reserve(10);cout after reserve(10) endl;cout v.size() v.size() endl;cout v.capacity() v.capacity() endlendl;v.shrink_to_fit();cout after shrink_to_fit() endl;cout v.size() v.size() endl;cout v.capacity() v.capacity() endl endl;return 0; }输出 v.size()5 v.capacity()5 after reserve(10) v.size()5 v.capacity()10 after shrink_to_fit() v.size()5 v.capacity()5 2、修改操作pop_back()、push_back //vector 容器。 #include iostream #include vector #includestring using namespace std; int main() {vectorstring v{ one,two,three,four,five }; v.pop_back();v.push_back(six);for (auto it v.begin(); it v.end(); it)cout *it ;cout endl; }输出 one two three four six 3、修改操作insert() 语法格式用法说明iterator insert(pos,elem)在迭代器 pos 指定的位置之前插入一个新元素elem并返回表示新插入元素位置的迭代器。iterator insert(pos,n,elem)在迭代器 pos 指定的位置之前插入 n 个元素 elem并返回表示第一个新插入元素位置的迭代器。iterator insert(pos,first,last)在迭代器 pos 指定的位置之前插入其他容器不仅限于vector中位于 [first,last) 区域的所有元素并返回表示第一个新插入元素位置的迭代器。 //vector 容器。 #include iostream #include vector #includestring using namespace std; int main() {vectorstring v{ one,two,three,four,five }; v.insert(v.begin(),ten);for (auto it v.begin(); it v.end(); it)cout *it ;cout endl;v.insert(v.end(), { ten,ten2 });for (auto it v.begin(); it v.end(); it)cout *it ;cout endl;return 0; }输出 ten one two three four five ten one two three four five ten ten2 4、修改操作emplace() 是 C 11 标准新增加的成员函数用于在 vector 容器指定位置之前插入一个新的元素。 emplace() 每次只能插入一个元素而不是多个。 该函数的语法格式如下 iterator emplace (const_iterator pos, args…); 其中pos 为指定插入位置的迭代器args… 表示与新插入元素的构造函数相对应的多个参数该函数会返回表示新插入元素位置的迭代器。 //vector 容器。 #include iostream #include vector #includestring using namespace std; int main() {vectorstring v{ one,two,three,four,five }; //emplace() 每次只能插入一个 int 类型元素v.emplace(v.begin(),ten);for (auto it v.begin(); it v.end(); it)cout *it ;cout endl;return 0; }输出 ten one two three four five 5、修改操作erase()、swap()、clear() 、 //vector 容器。 #include iostream #include vector #includestring using namespace std; int main() {vectorstring v{ one,two,three,four,five }; v.erase(v.begin());for (auto it v.begin(); it v.end(); it)cout *it ;cout endl;vectorstring w{ 1,12 };v.swap(w);for (auto it v.begin(); it v.end(); it)cout *it ;cout endl;v.clear();for (auto it v.begin(); it v.end(); it)cout *it ;cout endl;return 0; }输出 two three four five 1 12 , 6、emplace_back()和push_back()的区别 该函数是 C 11 新增加的其功能和 push_back() 相同都是在 vector 容器的尾部添加一个元素。emplace_back() 和 push_back() 的区别就在于底层实现的机制不同。push_back() 向容器尾部添加元素时首先会创建这个元素然后再将这个元素拷贝或者移动到容器中如果是拷贝的话事后会自行销毁先前创建的这个元素而 emplace_back() 在实现时则是直接在容器尾部创建这个元素省去了拷贝或移动元素的过程。 7、insert()和emplace() 既然 emplace() 和 insert() 都能完成向 vector 容器中插入新元素那么谁的运行效率更高呢 答案是 emplace()。 假如我们通过 insert() 函数向 vector 容器中插入 testDemo 类对象需要调用类的构造函数和移动构造函数或拷贝构造函数而通过 emplace() 函数实现同样的功能只需要调用构造函数即可。 同std::list、std::deque #include vector #include iostream using namespace std; class testDemo { public:testDemo(int num) :num(num) {std::cout 调用构造函数 endl;}testDemo(const testDemo other) :num(other.num) {std::cout 调用拷贝构造函数 endl;}testDemo(testDemo other) :num(other.num) {std::cout 调用移动构造函数 endl;}testDemo operator(const testDemo other); private:int num; }; testDemo testDemo::operator(const testDemo other) {this-num other.num;return *this; } int main() {cout insert: endl;std::vectortestDemo demo2{};demo2.insert(demo2.begin(), testDemo(1));cout emplace: endl;std::vectortestDemo demo1{};demo1.emplace(demo1.begin(), 1);return 0; }输出 insert: 调用构造函数 调用移动构造函数 emplace: 调用构造函数 参考 1、C STL 容器库 中文文档 2、STL教程C STL快速入门 3、https://www.apiref.com/cpp-zh/cpp/header.html 4、https://en.cppreference.com/w/cpp/container
http://www.w-s-a.com/news/969619/

相关文章:

  • 网站建设如何上传文件wordpress列表自定义数据表
  • 摄影课程自学网站科技项目的类型有
  • 未来最紧缺的十大专业长春seo顾问
  • 为什么点不开网站公关公司是做什么的
  • wordpress主要菜单如何对网站页面进行优化
  • 建设银行深分行圳招聘网站建立互联网公司网站
  • 湖南做旅游网站哪家最好html5手机网站免费模板
  • 云服务器上放多个网站wordpress ping大全
  • 以下属于网站的管理 更新 维护如何才能做好品牌网站建设
  • 国家工业和信息化部网站备案系统网站建设设计费用
  • 网站建设利弊宁波高端网站建设联系方式
  • 网站订票策划方案郑州代做网站
  • 免费的网站加速器注册公司邮箱
  • 千助网站建设网站整站程序
  • 自学建网站做网站优化访问网站出现目录
  • 济南网站建设是什么百度官网登录入口手机版
  • net快速建站西宁手机网站建设
  • 网站浏览器不兼容怎么办软件系统开发大概多少钱
  • 网站建设哪个公司最好shift wordpress
  • 公司网站建设功能介绍室内设计学习
  • 做网站策划容易遇到哪些问题沈阳公司网站制作
  • 做php网站都用框架吗网站备案当面核验拍摄照片
  • 泉州企业自助建站兰州最好的互联网公司
  • 监察部门网站建设方案网站seo技术教程
  • 个人网站制作源代码下载品牌建设部
  • 网站备案需要准备什么文创产品设计思路
  • 网站开发书籍推荐青岛城阳新闻最新消息
  • 秦皇岛网站建设服务聊城做网站的公司资讯
  • 30岁转行做网站设计丰涵网站建设
  • 山东省和住房建设厅网站首页开发商不按时交房可以退房吗