std::basic_string<CharT,Traits,Allocator>::starts_with
提供: cppreference.com
< cpp | string | basic string
| bool starts_with(std::basic_string_view<CharT, Traits> x) const noexcept; |
(1) | (C++20以上) |
| bool starts_with(CharT x) const noexcept; |
(2) | (C++20以上) |
| bool starts_with(const CharT* x) const; |
(3) | (C++20以上) |
文字列が指定された接頭辞で始まるかどうか調べます。
1) 接頭辞は文字列ビューです (別の
std::basic_string から暗黙に変換された結果かもしれません)。2) 接頭辞は単一の文字です。
3) 接頭辞は C スタイルの文字です。
3つのオーバーロードはすべて実質的に std::basic_string_view<CharT, Traits>(data(), size()).starts_with(x); を返します。
目次 |
[編集] 引数
| x | - | 文字列の先頭と比較する文字シーケンスまたは単一の文字。 |
[編集] 戻り値
文字列が指定された接頭辞で始まるならば true、そうでなければ false。
[編集] 例
Run this code
#include <iostream> #include <string_view> #include <string> template <typename PrefixType> void test_prefix_print(const std::string& str, PrefixType prefix) { std::cout << '\'' << str << "' starts with '" << prefix << "': " << str.starts_with(prefix) << '\n'; } int main() { std::boolalpha(std::cout); auto helloWorld = std::string("hello world"); test_prefix_print(helloWorld, std::string_view("hello")); test_prefix_print(helloWorld, std::string_view("goodby")); test_prefix_print(helloWorld, 'h'); test_prefix_print(helloWorld, 'x'); }
出力:
'hello world' starts with 'hello': true 'hello world' starts with 'goodby': false 'hello world' starts with 'h': true 'hello world' starts with 'x': false
[編集] 関連項目
| (C++20) |
文字列が指定された接尾辞で終わるか調べます (パブリックメンバ関数) |
| (C++20) |
文字列ビューが指定された接頭辞で始まるか調べます ( std::basic_string_view<CharT,Traits>のパブリックメンバ関数)
|
| (C++20) |
文字列ビューが指定された接尾辞で終わるか調べます ( std::basic_string_view<CharT,Traits>のパブリックメンバ関数)
|
| 2つの文字列を比較します (パブリックメンバ関数) | |
| 部分文字列を返します (パブリックメンバ関数) |

