string::get_allocator

allocator_type get_allocator() const noexcept;

返回和对象相关的分配器的一个拷贝

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
vector<char> myv;
char *p;
unsigned int i;
p = myv.get_allocator().allocate(5);
for(i = 0; i< 5; i++)
myv.get_allocator().construct(&p[i], 63 + i);
cout << "the allocated array contains:";
for(i = 0; i< 5; i++)
cout << p[i] << ' ';
cout << endl;
for(i = 0; i < 5; i++)
myv.get_allocator().destroy(&p[i]);
myv.get_allocator().deallocate(p, 5);
}

原文地址:https://www.cnblogs.com/xpylovely/p/12125761.html