1. <legend id='MrE5d'><style id='MrE5d'><dir id='MrE5d'><q id='MrE5d'></q></dir></style></legend>
      <tfoot id='MrE5d'></tfoot>

      <small id='MrE5d'></small><noframes id='MrE5d'>

      <i id='MrE5d'><tr id='MrE5d'><dt id='MrE5d'><q id='MrE5d'><span id='MrE5d'><b id='MrE5d'><form id='MrE5d'><ins id='MrE5d'></ins><ul id='MrE5d'></ul><sub id='MrE5d'></sub></form><legend id='MrE5d'></legend><bdo id='MrE5d'><pre id='MrE5d'><center id='MrE5d'></center></pre></bdo></b><th id='MrE5d'></th></span></q></dt></tr></i><div id='MrE5d'><tfoot id='MrE5d'></tfoot><dl id='MrE5d'><fieldset id='MrE5d'></fieldset></dl></div>
      • <bdo id='MrE5d'></bdo><ul id='MrE5d'></ul>

      向量与字符串

      时间:2023-09-15
    1. <small id='4V5mi'></small><noframes id='4V5mi'>

      <tfoot id='4V5mi'></tfoot>
    2. <legend id='4V5mi'><style id='4V5mi'><dir id='4V5mi'><q id='4V5mi'></q></dir></style></legend>
          <bdo id='4V5mi'></bdo><ul id='4V5mi'></ul>

              <tbody id='4V5mi'></tbody>
                <i id='4V5mi'><tr id='4V5mi'><dt id='4V5mi'><q id='4V5mi'><span id='4V5mi'><b id='4V5mi'><form id='4V5mi'><ins id='4V5mi'></ins><ul id='4V5mi'></ul><sub id='4V5mi'></sub></form><legend id='4V5mi'></legend><bdo id='4V5mi'><pre id='4V5mi'><center id='4V5mi'></center></pre></bdo></b><th id='4V5mi'></th></span></q></dt></tr></i><div id='4V5mi'><tfoot id='4V5mi'></tfoot><dl id='4V5mi'><fieldset id='4V5mi'></fieldset></dl></div>

                本文介绍了向量与字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                C++ std::vector 和 std::basic_string 之间的根本区别是什么(如果有的话)?

                What is the fundamental difference, if any, between a C++ std::vector and std::basic_string?

                推荐答案

                • basic_string 不会调用其元素的构造函数和析构函数.矢量确实如此.

                  • basic_string doesn't call constructors and destructors of its elements. vector does.

                    交换 basic_string 会使迭代器失效(启用小字符串优化),交换向量不会.

                    swapping basic_string invalidates iterators (enabling small string optimization), swapping vectors doesn't.

                    basic_string 内存在 C++03 中不能连续分配.向量总是连续的.这个区别在 C++0x [string.require] 中被移除了:

                    basic_string memory may not be allocated continuously in C++03. vector is always continuous. This difference is removed in C++0x [string.require]:

                    basic_string 对象中的类似字符的对象应连续存储

                    The char-like objects in a basic_string object shall be stored contiguously

                  • basic_string 具有字符串操作的接口.向量没有.

                  • basic_string has interface for string operations. vector doesn't.

                    basic_string 可以使用写时复制策略(在 C++11 之前).矢量不能.

                    basic_string may use copy on write strategy (in pre C++11). vector can't.

                    非信徒的相关引述:

                    [基本字符串]:

                    类模板 basic_string 符合 Sequence Container (23.2.3) 的要求,对于一个Reversible Container (23.2),以及一个 Allocator-aware 的容器(表 99),除了 basic_string不使用 allocator_traits::construct 和 allocator_- 构造或销毁其元素traits::destroy 和用于 basic_string 的 swap() 使迭代器失效.支持的迭代器通过 basic_string 是随机访问迭代器(24.2.7).

                    The class template basic_string conforms to the requirements for a Sequence Container (23.2.3), for a Reversible Container (23.2), and for an Allocator-aware container (Table 99), except that basic_string does not construct or destroy its elements using allocator_traits::construct and allocator_- traits::destroy and that swap() for basic_string invalidates iterators. The iterators supported by basic_string are random access iterators (24.2.7).

                    这篇关于向量与字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:STL 容器的内存消耗 下一篇:编译器不推导出模板参数(映射 std::vector -> st

                相关文章

                最新文章

                <tfoot id='UCgb6'></tfoot>
                • <bdo id='UCgb6'></bdo><ul id='UCgb6'></ul>
                <i id='UCgb6'><tr id='UCgb6'><dt id='UCgb6'><q id='UCgb6'><span id='UCgb6'><b id='UCgb6'><form id='UCgb6'><ins id='UCgb6'></ins><ul id='UCgb6'></ul><sub id='UCgb6'></sub></form><legend id='UCgb6'></legend><bdo id='UCgb6'><pre id='UCgb6'><center id='UCgb6'></center></pre></bdo></b><th id='UCgb6'></th></span></q></dt></tr></i><div id='UCgb6'><tfoot id='UCgb6'></tfoot><dl id='UCgb6'><fieldset id='UCgb6'></fieldset></dl></div>

                <small id='UCgb6'></small><noframes id='UCgb6'>

                  1. <legend id='UCgb6'><style id='UCgb6'><dir id='UCgb6'><q id='UCgb6'></q></dir></style></legend>