std::basic_string<CharT,Traits,Allocator>::ends_with
提供: cppreference.com
<tbody>
</tbody>
constexpr bool ends_with( std::basic_string_view<CharT,Traits> sv ) const noexcept; |
(1) | (C++20以上) |
constexpr bool ends_with( CharT c ) const noexcept; |
(2) | (C++20以上) |
constexpr bool ends_with( const CharT* s ) const; |
(3) | (C++20以上) |
文字列が指定された接尾辞で終わるかどうか調べます。 接尾辞は以下のいずれかです。
1) 文字列ビュー
sv。 別の std::basic_string から暗黙に変換された結果でも構いません。2) 単一の文字
c。3) ヌル終端文字列
s。3つのオーバーロードはすべて実質的に std::basic_string_view<CharT, Traits>(data(), size()).ends_with(x); を返します (ただし x は引数です)。
引数
| sv | - | 文字列ビュー。 別の std::basic_string から暗黙に変換された結果でも構いません。
|
| c | - | 単一の文字。 |
| s | - | ヌル終端文字列。 |
戻り値
文字列が指定された接尾辞で終わるならば true、そうでなければ false。
例
Run this code
#include <iostream>
#include <string_view>
#include <string>
template <typename SuffixType>
void test_suffix_print(const std::string& str, SuffixType suffix)
{
std::cout << '\'' << str << "' ends with '" << suffix << "': " <<
str.ends_with(suffix) << '\n';
}
int main()
{
std::boolalpha(std::cout);
auto helloWorld = std::string("hello world");
test_suffix_print(helloWorld, std::string_view("world"));
test_suffix_print(helloWorld, std::string_view("goodbye"));
test_suffix_print(helloWorld, 'd');
test_suffix_print(helloWorld, 'x');
}
出力:
'hello world' ends with 'world': true
'hello world' ends with 'goodbye': false
'hello world' ends with 'd': true
'hello world' ends with 'x': false
関連項目
(C++20) |
文字列が指定された接頭辞で始まるか調べます (パブリックメンバ関数) |
(C++20) |
文字列ビューが指定された接頭辞で始まるか調べます ( std::basic_string_view<CharT,Traits>のパブリックメンバ関数)
|
(C++20) |
文字列ビューが指定された接尾辞で終わるか調べます ( std::basic_string_view<CharT,Traits>のパブリックメンバ関数)
|
| 2つの文字列を比較します (パブリックメンバ関数) | |
| 部分文字列を返します (パブリックメンバ関数) |