清單::get_allocator()是C++ STL中的內置函數,用於獲取容器列表的分配器。
用法:
Allocator_type get_allocator()
參數:此函數沒有任何參數。
返回值:返回與列表關聯的分配器。
下麵的程序清楚地說明了列表:: get_allocator()函數。示例1:
// C++ program to understand
// about list getallocator method
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
// Creating a container of type list
list<int> 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 <bits/stdc++.h>
using namespace std;
int main(void)
{
// Creating a container of type list
list<string> 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++ list::emplace_front()、list::emplace_back()用法及代碼示例
- C++ list::pop_front()、list::pop_back()用法及代碼示例
- C++ list::remove()、list::remove_if()用法及代碼示例
- C++ list::empty()、list::size()用法及代碼示例
- C++ list::front()、list::back()用法及代碼示例
- C++ list::push_front()、list::push_back()用法及代碼示例
- C++ list::begin()、list::end()用法及代碼示例
- C++ list insert()用法及代碼示例
- C++ 嵌套list用法及代碼示例
- C++ list::swap()用法及代碼示例
- C++ list::operator=用法及代碼示例
- C++ std::list::sort用法及代碼示例
注:本文由純淨天空篩選整理自ankit15697大神的英文原創作品 list get_allocator in C++ STL。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。