Vector vs string

前端 未结 7 671
挽巷
挽巷 2020-12-06 09:46

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

7条回答
  •  隐瞒了意图╮
    2020-12-06 10:21

    A vector is a data structure which simulates an array. Deep inside it is actually a (dynamic) Array.

    The basic_string class represents a Sequence of characters. It contains all the usual operations of a Sequence, and, additionally, it contains standard string operations such as search and concatenation.

    You can use vector to keep whatever data type you want std::vector or or even std::vector< std::vector > but a basic_string can only be used for representing "text".

提交回复
热议问题