basic_string::get_allocator
用于返回的对象分配程序的复制构造字符串。
allocator_type get_allocator( ) const;
返回值
字符串使用的分配器。
备注
成员函数返回存储的程序分配对象。
字符串类的分配器指定类如何管理存储。 默认分配程序都附有容器类用于大多数编程的需要即可。 拥有分配编写和使用程序类是高级 C++ 主题。
示例
// basic_string_get_allocator.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
// The following lines declare objects
// that use the default allocator.
string s1;
basic_string <char> s2;
basic_string <char, char_traits< char >, allocator< char > > s3;
// s4 will use the same allocator class as s1
basic_string <char> s4( s1.get_allocator ( ) );
basic_string <char>::allocator_type xchar = s1.get_allocator( );
// You can now call functions on the allocator class xchar used by s1
}
要求
标头:< 字符串>
命名空间: std