命名空间
变体
操作

std::experimental::basic_string_view<CharT,Traits>::operator[]

来自 cppreference.cn
 
 
实验性的
技术规范
文件系统库 (filesystem TS)
库基础 (library fundamentals TS)
库基础 2 (library fundamentals TS v2)
库基础 3 (library fundamentals TS v3)
并行性扩展 (parallelism TS)
并行性扩展 2 (parallelism TS v2)
并发性扩展 (concurrency TS)
并发性扩展 2 (concurrency TS v2)
概念 (concepts TS)
范围 (ranges TS)
反射 (reflection TS)
数学特殊函数 (special functions TR)
实验性的非 TS
模式匹配
线性代数
std::execution
契约
2D 图形
 
 
 
constexpr const_reference operator[](size_type pos) const;
(库基础 TS)

返回到指定位置 pos 处字符的常量引用。

不执行边界检查:如果 pos >= size(),则行为未定义。

目录

[编辑] 参数

pos - 要返回的字符的位置

[编辑] 返回值

到请求字符的常量引用

[编辑] 异常

不抛出

[编辑] 复杂度

常数。

[编辑] 注意

std::basic_string::operator[] 不同,basic_string_view::operator[](size()) 具有未定义的行为,而不是返回 CharT()

[编辑] 示例

#include <iostream>
#include <experimental/string_view>
int main()
{
    std::string str = "Exemplar";
    std::experimental::string_view v = str;
    std::cout << v[2] << '\n';
//  v[2] = 'y'; // Error: cannot modify through a string view
    str[2] = 'y';
    std::cout << v[2] << '\n';
}

输出

e
y

[编辑] 参见

访问带有边界检查的指定字符
(公共成员函数) [编辑]