vector<string>& GetVecStrSerial()
时间: 2023-05-27 14:05:06 浏览: 85
泛型类vector<T>源码分析
The vector<string> is a data structure in C++ that is used to store a collection of strings. It is a dynamic array that can grow or shrink as needed, and provides efficient random access to its elements.
To use a vector<string>, you first need to include the <vector> header file:
```
#include <vector>
```
Then, you can create a vector<string> object like this:
```
std::vector<std::string> myVector;
```
To add elements to the vector, you can use the push_back() method:
```
myVector.push_back("hello");
myVector.push_back("world");
```
You can access elements in the vector using the [] operator:
```
std::cout << myVector[0] << std::endl; // prints "hello"
```
You can also iterate over the vector using a for loop:
```
for (int i = 0; i < myVector.size(); i++) {
std::cout << myVector[i] << std::endl;
}
```
To remove an element from the vector, you can use the erase() method:
```
myVector.erase(myVector.begin() + 1); // removes the second element
```
The vector<string> also provides other useful methods such as clear(), size(), and empty().
阅读全文