std::experimental::basic_string_view<CharT,Traits>:: operator[]
From cppreference.net
<
cpp
|
experimental
|
basic string view
|
constexpr
const_reference operator
[
]
(
size_type pos
)
const
;
|
(ライブラリファンダメンタル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
関連項目
|
境界チェック付きで指定された文字にアクセス
(公開メンバ関数) |