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,&*(s.begin() + n) == &*s.begin() + n[0, s.size())任何中的n,或者,等价地,一个指针到s[0]可以传递给预期一个charT[]阵列的第一个元素的指针的函数。 (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. (C++11 起)为常见字符类型提供的一些特化类:
| 在头文件
<string> 中定义 | |
| 类型 | Definition |
| 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> |
[编辑] 成员类型
| 成员类型 | Definition |
traits_type
|
Traits
|
value_type
|
Traits::char_type
|
allocator_type
|
Allocator
|
size_type
|
无符号整数类型(通常是size_t)
原文: Unsigned integral type (usually size_t) |
difference_type
|
有符号整型(通常是ptrdiff_t) |
reference
|
Allocator::reference (至 C++11)value_type& (C++11 起)
|
const_reference
|
Allocator::const_reference (至 C++11)const value_type& (C++11 起)
|
pointer
|
Allocator::pointer (至 C++11)std::allocator_traits<Allocator>::pointer (C++11 起) |
const_pointer
|
Allocator::const_pointer (至 C++11) std::allocator_traits<Allocator>::const_pointer (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 number of characters (公共成员函数) | |
| 返回的最大字符数 原文: 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 (公共成员函数) |
| |
| 清除其内容 (公共成员函数) | |
| 插入字符 (公共成员函数) | |
| removes characters (公共成员函数) | |
| 添加一个字符的结束 (公共成员函数) | |
| (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 (公共静态成员常量) |
[编辑] 非成员函数
| 连接两个字符串或一个字符串和一个字符 原文: concatenates two strings or a string and a char (函数模板) | |
| 按字典顺序比较两个字符串 原文: 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 (函数) |
[编辑] Helper类
| (C++11) (C++11) (C++11) (C++11) |
字符串哈希支持 (类模板特化) |