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

来源:互联网 发布:md5算法基本过程 编辑:程序博客网 时间:2024/06/04 18:56
  • c++ string 类小结(增加c++11标准):

  • 成员类型


    成员类型定义traits_type第一个模板参数 Traitsvalue_typeTraits::char_typeallocator_type第三个模板参数 Allocsize_type无符号整数类型(通常为 size_tdifference_type有符号整数类型(通常为 ptrdiff_treferenceAllocator::reference 已弃用
    value_type& C++11const_referenceAllocator::const_reference 已弃用
    const value_type& C++11pointerAllocator::pointer 已弃用
    std::allocator_traits<Allocator>::pointer C++11const_pointerAllocator::const_pointer 已弃用
    std::allocator_traits<Allocator>::const_pointer C++11iterator随机访问迭代器const_iterator常量随机访问迭代器reverse_iteratorstd::reverse_iterator<iterator>const_reverse_iteratorstd::reverse_iterator<const_iterator>
  • 成员函数


    (constructor)构造对象(destructor)析构对象operator=赋值操作

    迭代器

    begin返回指向字符串起始位置的迭代器(iteratorend返回指向字符串末尾位置的迭代器rbegin返回指向字符串逆序起始位置的逆序迭代器(reverse_iteratorrend返回指向字符串逆序末尾位置的逆序迭代器cbegin C++11返回指向字符串起始位置的常迭代器(const_iteratorcend C++11返回指向字符串末尾位置的常迭代器crbegin C++11返回指向字符串逆序起始位置的常逆序迭代器(const_reverse_iteratorcrend 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比较字符串
  • 常量


    npossize_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++11std::hash<std::u32string> C++11std::hash<std::wstring> C++11
0 0
原创粉丝点击