string简介及其使用

注:std::string C++11标准。

string概述

typedef basic_string<char> string;

字符串是表示字符序列的对象。
标准string类使用类似于字节标准容器的接口提供对此类对象的支持,但是添加了专门用于操作单字节字符(single-byte characters)字符串的特性。
string类是basic_string类模板的实例化,该模板使用char作为其字符类型,并具有默认的char_traits和allocator类型。
需要注意的是,这个类独立于所使用的编码来处理字节(即与编码无关):如果用于处理多字节或可变长度字符(如UTF-8)的序列,那么这个类的所有成员(如长度或大小)及其迭代器仍将以字节(而不是实际编码的字符)进行操作。

成员类型

member type definition
value_type char
traits_type char_traits<char>
allocator_type allocator<char>
reference char&
const_reference const char&
pointer char*
const_pointer const char*
iterator random access iterator to char (convertible to const_iterator)
const_iterator random access iterator to const char
reverse_iterator reverse_iterator<iterator>
const_reverse_iterator reverse_iterator<const_iterator>
difference_type ptrdiff_t
size_type size_t

成员函数

(constructor) 构造函数

(destructor) 析构函数

operator= 赋值

猜你喜欢

转载自www.cnblogs.com/leaves1024/p/10270753.html