std::strpbrk
From cppreference.com
| ヘッダー <cstring> で定義 |
||
| const char* strpbrk( const char* dest, const char* breakset ); |
||
| char* strpbrk( char* dest, const char* breakset ); |
||
dest が指すヌル終端バイト文字列を、breakset が指すヌル終端バイト文字列内の任意の文字について走査し、その文字へのポインタを返します。
目次 |
[編集] パラメータ
| dest | - | 解析対象のヌル終端バイト文字列へのポインタ |
| breakset | - | 検索対象の文字を含むヌル終端バイト文字列へのポインタ |
[編集] 返り値
dest 内で、かつ breakset 内にも存在する最初の文字へのポインタ。そのような文字が存在しない場合はヌルポインタ。
[編集] 備考
"string pointer break" の略で、区切り文字("break")の最初の文字へのポインタを返すことに由来します。
[編集] 例
このコードを実行
#include <cstring> #include <iomanip> #include <iostream> int main() { const char* str = "hello world, friend of mine!"; const char* sep = " ,!"; unsigned int cnt = 0; do { str = std::strpbrk(str, sep); // find separator std::cout << std::quoted(str) << '\n'; if (str) str += std::strspn(str, sep); // skip separator ++cnt; // increment word count } while (str && *str); std::cout << "There are " << cnt << " words\n"; }
出力
" world, friend of mine!" ", friend of mine!" " of mine!" " mine!" "!" There are 5 words
[編集] 関連項目
| 以下から成る最大の初期セグメントの長さを返す 別のバイト文字列に含まれない文字のみ (関数) | |
| バイト文字列内の次のトークンを見つける (関数) | |
| 最初に出現する文字を見つける (関数) | |
| あるワイド文字列に含まれるいずれかのワイド文字が、別のワイド文字列内で最初に現れる場所を見つける (関数) | |
| C のドキュメント (strpbrk)
| |