c++ string 类小结(增加c++11标准)

  • c++ string 类小结(增加c++11标准):

  • 成员类型 定义
    traits_type 第一个模板参数 Traits
    value_type Traits::char_type
    allocator_type 第三个模板参数 Alloc
    size_type 无符号整数类型(通常为 size_t
    difference_type 有符号整数类型(通常为 ptrdiff_t
    reference Allocator::reference 已弃用
    value_type& C++11
    const_reference Allocator::const_reference 已弃用
    const value_type& C++11
    pointer Allocator::pointer 已弃用
    std::allocator_traits<Allocator>::pointer C++11
    const_pointer Allocator::const_pointer 已弃用
    std::allocator_traits<Allocator>::const_pointer C++11
    iterator 随机访问迭代器
    const_iterator 常量随机访问迭代器
    reverse_iterator std::reverse_iterator<iterator>
    const_reverse_iterator std::reverse_iterator<const_iterator>
  • (constructor) 构造对象
    (destructor) 析构对象
    operator= 赋值操作

    迭代器

    begin 返回指向字符串起始位置的迭代器(iterator
    end 返回指向字符串末尾位置的迭代器
    rbegin 返回指向字符串逆序起始位置的逆序迭代器(reverse_iterator
    rend 返回指向字符串逆序末尾位置的逆序迭代器
    cbegin C++11 返回指向字符串起始位置的常迭代器(const_iterator
    cend C++11 返回指向字符串末尾位置的常迭代器
    crbegin C++11 返回指向字符串逆序起始位置的常逆序迭代器(const_reverse_iterator
    crend C++11 返回指向字符串逆序末尾位置的常逆序迭代器

    元素数量

    size 返回有效字符个数
    length 返回有效字符个数,跟 size 返回相同的值
    max_size 返回支持的最大字符个数
    resize 改变有效字符个数
    capacity 返回当前可使用的最大字符内存块数(即存储容器)
    reserve 请求改变存储容量
    clear 清空字符串
    empty 检测字符串是否是空的
    shrink_to_fit C++11 请求移除未使用的存储空间

    元素访问

    operator[] 访问字符
    at 访问字符
    back C++11 访问最后一个字符
    front C++11 访问第一个字符

    修改器

    operator+= 附加(Append)到字符串
    append 附加到字符串
    push_back 附加字符到字符串
    assign 赋值内容到字符串
    insert 插入到字符串
    erase 从字符串中清除字符
    replace 替换字符串的部分内容
    swap 交换字符串对象
    pop_back C++11 删除最后一个字符

    字符串操作

    c_str 返回 C 型字符串
    data 返回字符串数据
    get_allocator 获得内存分配器
    copy 从字符串中拷贝字符序列
    find 从字符串查找字符或字符串,返回第一次找到的位置
    rfind 从从字符串查找字符或字符串,返回最后一次找到的位置
    find_first_of 从字符串查找(由参数确定的)任意匹配的字符,返回第一次找到的位置
    find_last_of 从字符串查找(由参数确定的)任意匹配的字符,返回最后一次找到的位置
    find_first_not_of 从字符串查找(由参数确定的)任意不匹配的字符,返回第一次找到的位置
    find_last_not_of 从字符串查找(由参数确定的)任意不匹配的字符,返回最后一次找到的位置
    substr 产生子串
    compare 比较字符串
  • npos size_type 的最大值
  • std::operator+(std::string) 连接两个字符串或一个字符串和一个字符
    operator==
    operator!=
    operator<
    operator>
    operator<=
    operator>=
    按字典序比较两个字符串
    std::swap(std::string) 特例化 std::swap 函数模板
    operator<<
    operator>>
    对字符串进行流输入或输出操作
    std::getline(std::string) 从流中读取一行字符
  • std::stoi C++11 将字符串转化成带符号(Signed)整数
    std::stol C++11 将字符串转化成带符号整数
    std::stoll C++11 将字符串转化成带符号整数
    std::stoul C++11 将字符串转化成无符号(Unsigned)整数
    std::stoull C++11 将字符串转化成无符号整数
    std::stof C++11 将字符串转化成浮点数
    std::stod C++11 将字符串转化成浮点数
    std::stold C++11 将字符串转化成浮点数
    std::to_string C++11 将一个整数或浮点数转化成字符串
    std::to_wstring C++11 将一个整数或浮点数转化成宽字符串
    std::hash<std::string> C++11 字符串的啥希(Hash)支持
    std::hash<std::u16string> C++11
    std::hash<std::u32string> C++11
    std::hash<std::wstring> C++11
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值