From a purely philosophical point of view: yes, a string is a type of vector. This is a continuous memory block in which characters are stored (a vector is a continuous memory block in which objects of arbitrary types are stored). So, from this point of view, a string is a special kind of vector.
From the point of view of design and implementation, std::string and std::vector they have the same interface elements (for example, adjacent memory blocks, operator[] ), but std::string does not follow from std::vector (reverse note: you should not be publicly deduced from standard containers, since they are not intended for classes, for example, they do not have virtual destructors), and they cannot be directly converted to each other. That is, the following will not compile:
std::string s = "abc"; std::vector<char> v = s;
However, since both of them support an iterator, you can convert the string to a vector:
std::string s = "abc"; std::vector<char> v(s.begin(), s.end());
std::string will no longer have a reference counter (as in C ++ 11) as a copy-to-write function, which was used in many implementations of the C ++ 11 standard.
From a memory point of view, an instance of std::string will be very similar to std::vector<char> (for example, both of them will have a pointer to their location in memory, size, capacity), but the functionality of the two classes is different.
source share