名前空間
変種
操作

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

From cppreference.com
 
 
 
 
 
constexpr const_reference operator[](size_type pos) const;
(Library Fundamentals TS)

指定された位置posにある文字へのconst参照を返します。

境界チェックは行われません。pos >= size() の場合、動作は未定義です。

目次

[編集] パラメータ

pos - 返される文字の位置

[編集] 戻り値

要求された文字へのconst参照

[編集] 例外

投げません

[編集] 複雑さ

定数。

[編集] 注意

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

[編集] 関連項目

境界チェック付きで指定された文字にアクセス
(public member function) [編集]
English 日本語 中文(简体) 中文(繁體)