std::basic_string<CharT,Traits,Allocator>::ends_with
From cppreference.com
< cpp | string | basic string
| constexpr bool ends_with( std::basic_string_view<CharT, Traits> sv ) const noexcept; |
(1) | (C++20以降) |
| constexpr bool ends_with( CharT ch ) const noexcept; |
(2) | (C++20以降) |
| constexpr bool ends_with( const CharT* s ) const; |
(3) | (C++20以降) |
文字列が指定されたサフィックスで終わるかどうかをチェックします。サフィックスは以下のいずれかです。
1) 文字列ビュー sv (これは、別の
std::basic_string からの暗黙的な変換の結果である場合があります)。2) 単一の文字 ch。
3) ヌル終端文字文字列 s。
3つのオーバーロードはすべて、実質的に std::basic_string_view<CharT, Traits>(data(), size()).ends_with(x) を返します。ここで、x はパラメーターです。
目次 |
[編集] パラメーター
| sv | - | 別の std::basic_string からの暗黙的な変換の結果である可能性のある文字列ビュー |
| 文字 | - | 単一の文字 |
| s | - | ヌル終端文字文字列 |
[編集] 戻り値
文字列が指定されたサフィックスで終わる場合は true、そうでない場合は false。
[編集] 備考
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_starts_ends_with |
201711L |
(C++20) | 文字列のプレフィックスとサフィックスのチェック: starts_with() および ends_with() |
[編集] 例
このコードを実行
#include <cassert> #include <string> #include <string_view> int main() { using namespace std::literals; const auto str = "Hello, C++20!"s; assert ("" && str.ends_with("C++20!"sv) // (1) && !str.ends_with("c++20!"sv) // (1) && str.ends_with("C++20!"s) // (1) implicit conversion string to string_view && !str.ends_with("c++20!"s) // (1) implicit conversion string to string_view && str.ends_with('!') // (2) && !str.ends_with('?') // (2) && str.ends_with("C++20!") // (3) && !str.ends_with("c++20!") // (3) ); }
[編集] 関連項目
| (C++20) |
文字列が指定された接頭辞で始まるかをチェックする (public member function) |
| (C++20) |
string viewが指定されたプレフィックスで始まるかチェックする ( std::basic_string_view<CharT,Traits> の公開メンバ関数) |
| (C++20) |
string viewが指定されたサフィックスで終わるかチェックする ( std::basic_string_view<CharT,Traits> の公開メンバ関数) |
| (C++23) |
文字列が指定された部分文字列または文字を含むかをチェックする (public member function) |
| (C++23) |
string viewが指定された部分文字列または文字を含むかチェックする ( std::basic_string_view<CharT,Traits> の公開メンバ関数) |
| 2つの文字列を比較する (public member function) | |
| 部分文字列を返す (public member function) |