std::basic_string<CharT,Traits,Allocator>::operator[]
提供: cppreference.com
< cpp | string | basic string
(1) | ||
reference operator[]( size_type pos ); |
(C++20未満) | |
constexpr reference operator[]( size_type pos ); |
(C++20以上) | |
(2) | ||
const_reference operator[]( size_type pos ) const; |
(C++20未満) | |
constexpr const_reference operator[]( size_type pos ) const; |
(C++20以上) | |
指定された位置 pos
の文字を指す参照を返します。 範囲チェックは行われません。 pos > size() の場合、動作は未定義です。
1) pos == size() の場合、動作は未定義です。
2) pos == size() の場合、値 CharT() (ヌル文字) を指す参照が返されます。
|
(C++11未満) |
pos == size() の場合、値 CharT() (ヌル文字) を指す参照が返されます。 最初の (非 const の) バージョンでは、この文字が CharT() 以外の何らかの値に変更された場合、動作は未定義です 。 |
(C++11以上) |
目��� |
[編集] 引数
pos | - | 返す文字の位置 |
[編集] 戻り値
要求された文字を指す参照。
[編集] 計算量
一定。
[編集] 例
Run this code
#include <iostream> #include <string> int main() { std::string const e("Exemplar"); for (unsigned i = e.length() - 1; i != 0; i /= 2) std::cout << e[i]; std::cout << '\n'; const char* c = &e[0]; std::cout << c << '\n'; // print as a C string //Change the last character of s into a 'y' std::string s("Exemplar "); s[s.size()-1] = 'y'; std::cout << s << '\n'; }
出力:
rmx Exemplar Exemplary
[編集] 関連項目
境界チェック付きで指定された文字にアクセスします (パブリックメンバ関数) |