std::basic_string
来自cppreference.com
                    
                                        
                    
                    
                                                            
                    | 
   | 
  该页由英文版wiki使用Google Translate机器翻译而来。 
 该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里.  | 
|   在头文件 <string> 中定义
   | 
||
|   template<     class CharT,  | 
||
类模板
basic_string存储和处理字符类型的对象序列(即特化的std::char_traits对象或兼容的特性类)。 原文:
The class template 
basic_string stores and manipulates sequences of char-like objects (that is, objects for which a specialization of std::char_traits or compatible traits class is provided). basic_string中的元素连续存储,也就是说,对于一个basic_strings,[0, s.size())中的任意n都满足&*(s.begin() + n) == &*s.begin() + n,或者,与之等价,一个指向s[0]的指针可以传递给函数,这个函数接收charT[]数组第一个元素的指针。 (since C++11)原文:
The elements of a 
basic_string are stored contiguously, that is, for a basic_string s, &*(s.begin() + n) == &*s.begin() + n for any n in [0, s.size()), or, equivalently, a pointer to s[0] can be passed to functions that expect a pointer to the first element of a charT[] array. (since C++11)为常见字符类型提供的一些特化类:
|   在头文件  
<string> 中定义  | |
| 类型 | 定义 | 
| std::string | std::basic_string<char> | 
| std::wstring | std::basic_string<wchar_t> | 
| std::u16string | std::basic_string<char16_t> | 
| std::u32string | std::basic_string<char32_t> | 
[编辑] 成员类型
| 成员类型 | 定义 | 
  traits_type
 | 
  Traits
 | 
  value_type
 | 
  Traits::char_type
 | 
  allocator_type
 | 
  Allocator 
 | 
  size_type
 | 
无符号整型(通常是size_t) | 
  difference_type
 | 
有符号整型 (通常是ptrdiff_t) | 
  reference
 | 
  Allocator::reference (until C++11)value_type& (since C++11) 
 | 
  const_reference
 | 
  Allocator::const_reference (until C++11)const value_type& (since C++11) 
 | 
  pointer
 | 
  Allocator::pointer (until C++11)std::allocator_traits<Allocator>::pointer (since C++11)  | 
  const_pointer
 | 
  Allocator::const_pointer (until C++11) std::allocator_traits<Allocator>::const_pointer (since C++11)  | 
  iterator
 | 
  RandomAccessIterator 
 | 
  const_iterator
 | 
随机访问常迭代器 | 
  reverse_iterator
 | 
std::reverse_iterator<iterator> | 
  const_reverse_iterator
 | 
std::reverse_iterator<const_iterator> | 
[编辑] 成员函数
|     构造  basic_string (公共成员函数)  | |
|    为字符串赋值   (公共成员函数)  | |
|    为字符串赋值  (公共成员函数)  | |
|    返回关联的分配器   (公共成员函数)  | |
   
 | |
|     访问指定位置的字符,带边界检查  (公共成员函数)  | |
|     访问指定位置的字符  (公共成员函数)  | |
|    (C++11)  | 
    访问的第一个字符  (公共成员函数)  | 
|    (C++11)  | 
    访问的最后一个字符  (公共成员函数)  | 
|     返回一个指针,指向一个字符串的第一个字符  原文:  returns a pointer to the first character of a string (公共成员函数)  | |
|     返回一个不可修改的C风格字符串  原文:  returns a non-modifiable standard C character array version of the string (公共成员函数)  | |
   
 | |
|    (C++11)  | 
    返回指向字符串第一个元素的迭代器    原文:  returns an iterator to the beginning  (公共成员函数)  | 
|    (C++11)  | 
   
 	返回指向字符串尾端的迭代器    (公共成员函数)  | 
|    (C++11)  | 
    返回一个指向字符串最后一个元素的反向迭代器    原文:  returns a reverse iterator to the beginning  (公共成员函数)  | 
|    (C++11)  | 
   
 	返回一个指向字符串前端的反向迭代器   原文:  returns a reverse iterator to the end  (公共成员函数)  | 
   
 | |
|     检查字符串是否为空   (公共成员函数)  | |
|    返回字符数量   (公共成员函数)  | |
|     返回最大字符数量   原文:  returns the maximum number of characters  (公共成员函数)  | |
|     预留存储空间   (公共成员函数)  | |
|     返回当前分配的存储空间可容纳的最大字符数量   原文:  returns the number of characters that can be held in currently allocated storage  (公共成员函数)  | |
|    (C++11)  | 
    通过释放未使用的内存减少内存使用   原文:  reduces memory usage by freeing unused memory  (公共成员函数)  | 
   
 | |
|     删除全部内容   (公共成员函数)  | |
|     插入字符  (公共成员函数)  | |
|    删除字符   (公共成员函数)  | |
|     向末尾添加字符   (公共成员函数)  | |
|    (C++11)  | 
    删除最后一个字符   (公共成员函数)  | 
|     向末尾添加字符(串)   (公共成员函数)  | |
|     向末尾添加字符(串)   (公共成员函数)  | |
|     比较两个字符串  (公共成员函数)  | |
|     替换出现的每一个指定的字符  原文:  replaces every occurrence of specified characters (公共成员函数)  | |
|     返回子字符串  (公共成员函数)  | |
|     复制字符   (公共成员函数)  | |
|     改变存储的字符数   原文:  changes the number of characters stored  (公共成员函数)  | |
|     交换字符串的内容   (公共成员函数)  | |
   
 | |
|    在字符串中寻找字符(串)  (公共成员函数)  | |
|     寻找字符(串)最后一次出现的位置   原文:  find the last occurrence of a substring (公共成员函数)  | |
|     寻找字符串中任意字符第一次出现的位置   (公共成员函数)  | |
|     寻找字符串中任意字符第一次缺失的位置   (公共成员函数)  | |
|     寻找字符串中任意字符最后一次出现的位置   (公共成员函数)  | |
|    寻找字符串中任意字符最后一次缺失的位置   (公共成员函数)  | |
  
 | |
|     [静态的]</div></div>
  | 
    特殊值。确切的含义取决于具体情况。   原文:  special value. The exact meaning depends on the context (公共静态成员常量)  | 
[编辑] 非成员函数
|    连接两个字符串或字符和字符串   (函数模板)  | |
|     按字典顺序比较两个字符串   原文:  lexicographically compares two strings  (函数模板)  | |
|     特化的std::swap算法  (函数模板)  | |
   
 | |
|    在字符串上执行流式I/O   (函数模板)  | |
|     从的I/O流读取数据,并写入字符串   原文:  read data from an I/O stream into a string (函数)  | |
   
 | |
|    (C++11) (C++11) (C++11)  | 
    将字符串转换为有符号整数   原文:  converts a string to an signed integer  (函数)  | 
|    (C++11) (C++11)  | 
    将字符串转换为无符号整数   原文:  converts a string to an unsigned integer  (函数)  | 
|    (C++11) (C++11) (C++11)  | 
    将字符串转换为浮点值   原文:  converts a string to an floating point value  (函数)  | 
|    (C++11)  | 
    将整数或浮点值转换为  string 原文:  converts an integral or floating point value to  string (函数)  | 
|    (C++11)  | 
    将整数或浮点值转换为  wstring 原文:  converts an integral or floating point value to  wstring (函数)  | 
[编辑] 字面值
|   定义于  
std::literals::string_literals 名字空间  | |
|    (C++14)  | 
   将字符数组字面值转换为 basic_string  (函数)  | 
[编辑] 辅助类
|    (C++11) (C++11) (C++11) (C++11)  | 
    支持字符串的哈希函数   (类模板特化)  |