std::basic_string_view<CharT,Traits>::back
From cppreference.com
< cpp | string | basic string view
| constexpr const_reference back() const; |
(C++17以降) | |
ビューの最後の文字への参照を返します。`empty() == true` の場合、動作は未定義です。
目次 |
[編集] パラメータ
(なし)
[編集] 戻り値
最後の文字への参照。operator[](size() - 1) と等価です。
[編集] 計算量
定数。
[編集] 例
このコードを実行
#include <iostream> #include <string_view> int main() { for (std::string_view str{"ABCDEF"}; !str.empty(); str.remove_suffix(1)) std::cout << str.back() << ' ' << str << '\n'; }
出力
F ABCDEF E ABCDE D ABCD C ABC B AB A A
[編集] 関連項目
| 最初の文字にアクセスする (public member function) | |
| ビューが空かどうかをチェックする (public member function) | |
| (DR*) |
最後の文字にアクセスする ( std::basic_string<CharT,Traits,Allocator> の public メンバ関数) |