#include <string>
template<
typename CharT,
typename Traits = std::char_traits< CharT >,
typename Allocator = std::allocator< CharT >
> class basic_string;
类模板 basic_string 提供了字符序列如何操作和存储的泛型。下面是针对常见字符类型的特化:
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
typedef basic_string<char16_t> u16string; //C++0x 特征
typedef basic_string<char32_t> u32string; //C++0x 特征
类型成员
类型成员 | 定义 |
---|
traits_type | Traits |
value_type | Traits::char_type |
allocator_type | Allocator |
size_type | Allocator::size_type |
difference_type | Allocator::difference_type |
reference | Allocator::reference |
const_reference | Allocator::const_reference |
pointer | Allocator::pointer |
const_pointer | Allocator::const_pointer |
iterator | 随机访问迭代器 |
const_iterator | 常量随机访问迭代器 |
reverse_iterator | std::reverse_iterator<iterator> |
const_reverse_iterator | std::reverse_iterator<const_iterator> |
成员函数
元素访问
at | 访问指定字符,带有边界检查 |
[[operator_at | operator[] ]] | 访问指定字符 |
data | 返回一个指针,指向字符串第一个字符 |
c_str | 返回此字符串对应的标准C字符数组,不可修改 |
迭代器
容量
操作
查找
Allocator
常量
npos | 一个特殊值,用于指示 "未找到" 或 "所有剩下的字符" |
原文网址:http://zh.cppreference.com/w/cpp/string/basic_string