首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::basic_string_view

Defined in header <string_view>

template< class CharT, class Traits = std::char_traits<CharT> > class basic_string_view;

(since C++17)

类模板basic_string_view描述可以引用char-类似于序列的第一个元素位于零位置的对象。

典型的实现只包含两个成员:指向常量的指针。CharT还有一个尺码。

提供了几种常见字符类型的类型:

在头<字符串中定义[医]视图>

*。

类型定义

STD:字符串[医]意见STD::Basic[医]弦[医]视点<char>

STD::wstring[医]意见STD::Basic[医]弦[医]视图<wchar[医]T>

STD::u16字符串[医]意见STD::Basic[医]弦[医]视图<char16[医]T>

STD:u32string[医]意见STD::Basic[医]弦[医]视图<char32[医]T>

模板参数

CharT

-

character type

Traits

-

CharTraits class specifying the operations on the character type. Traits::char_type must name the same type as CharT.

成员类型

Member type

Definition

traits_type

Traits

value_type

CharT

pointer

CharT*

const_pointer

const CharT*

reference

CharT&

const_reference

const CharT&

const_iterator

implementation-defined constant RandomAccessIterator and ContiguousIterator whose value_type is CharT

iterator

const_iterator

reverse_iterator

const_reverse_iterator

const_reverse_iterator

std::reverse_iterator<const_iterator>

size_type

std::size_t

difference_type

std::ptrdiff_t

注:iteratorconst_iterator是相同的类型,因为字符串视图是常量字符序列中的视图。

成员函数

(constructor)

constructs a basic_string_view (public member function)

operator=

assigns a view (public member function)

迭代器

初学者将迭代器返回到开头%28的公共成员函数%29

Endcend将迭代器返回到End%28公共成员函数%29

将反向迭代器返回到开头%28的公共成员函数%29

rendcrend将反向迭代器返回到结束%28公共成员函数%29

元素存取

操作者。[访问指定字符%28公共成员函数%29

访问指定字符时,检查%28公共成员函数%29

前端访问第一个字符%28公共成员函数%29

返回访问最后一个字符%28公共成员函数%29

数据返回指向视图%28公共成员函数%29的第一个字符的指针。

容量

Szelength返回字符数%28公共成员函数%29

马克斯[医]Size返回最大字符数%28公共成员函数%29

空检查视图是否为空%28公共成员函数%29

修饰语者

移除[医]前缀通过将其启动向前移动到%28公共成员函数%29来缩小视图

移除[医]后缀通过向后移动视图的结束%28公共成员函数%29来缩小视图

交换交换内容%28公共成员函数%29

操作

复制字符%28公共成员函数%29

子字符串%28公共成员函数%29

比较两个视图%28公共成员函数%29

在视图%28公共成员函数%29中查找字符

查找子字符串%28公共成员函数%29的最后一次出现

找出[医]第一[医]第一次出现字符%28公共成员函数%29

找出[医]最后[医]查找最后出现的字符%28公共成员函数%29

找出[医]第一[医]不[医]查找第一次缺少字符%28公共成员函数%29

找出[医]最后[医]不[医]%28公共成员函数%29

常数

非营利组织静态特殊价值。确切意义取决于上下文%28公共静态成员常量%29

非会员职能

operator==operator!=operator<operator>operator<=operator>=

lexicographically compares two string views (function template)

输入/输出

运算符<<对字符串视图执行流输出%28函数模板%29

文字

定义在内联命名空间std::alals::string中[医]视点[医]文字

*。

运算符“SV%28C++17%29”创建字符数组文字%28函数%29的字符串视图。

帮助者类

std::hash<std::string_view>std::hash<std::wstring_view>std::hash<std::u16string_view>std::hash<std::u32string_view> (C++17)

hash support for string views (class template specialization)

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券