In C ++, the swap function empty container vctor

The swap function is a data exchange of two containers;

Realization of ideas: Create a container data (str_sq) and empty container vector of anonymous exchange of data, the data container emptying data.
Anonymous empty container will automatically be destroyed

Remember do not be emptied with a clear function in .empty () is 0 although the time, but the memory of the data is still there.

vector<string>().swap(str_sq);//清空容量

Guess you like

Origin blog.csdn.net/u013594490/article/details/92798039