list :: get_allocator()是C++ STL中的内置函数,用于获取容器列表的分配器。
句法:
Allocator_type get_allocator()
参数:此函数没有任何参数。
返回值:返回与列表关联的分配器。
下面的程序清楚地说明了list :: get_allocator()函数。
示例1:
// C++ program to understand
// about list getallocator method
#include
using namespace std;
int main(void)
{
// Creating a container of type list
list mylist;
// creating a pointer of type int
int* array;
// creating array using mylist get_allocator
array = mylist.get_allocator().allocate(3);
// inserting some data into the created array
for (int i = 0; i < 3; i++)
array[i] = i;
// printing details of the created array
for (int i = 0; i < 3; i++)
cout << array[i] << " ";
}
输出:
0 1 2
示例2:
// C++ program to understand
// about list getallocator method
#include
using namespace std;
int main(void)
{
// Creating a container of type list
list mylist;
// creating a pointer of type int
string* array;
// creating array using mylist get_allocator
array = mylist.get_allocator().allocate(3);
// inserting some data into array
array[0] = "Geeks";
array[1] = "For";
array[2] = "Geeks";
// printing details of array
for (int i = 0; i < 3; i++)
cout << array[i] << " ";
}
输出:
Geeks For Geeks
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程” 。