std::strpbrk - cppreference.com
提供: cppreference.com
<tbody> </tbody>
| ヘッダ |
||
|
|
||
|
|
||
breakset の指すヌル終端バイト文字列内の任意の文字を dest の指すヌル終端バイト文字列からスキャンし、その文字を指すポインタを返します。
引数
| dest | - | 解析するヌル終端バイト文字列を指すポインタ |
| breakset | - | 検索する文字を含むヌル終端バイト文字列を指すポインタ |
戻り値
breakset に含まれる dest 内の最初の文字を指すポインタ、またはそのような文字が存在しない場合はヌルポインタ。
ノート
関数名の由来は「string pointer break」です。 最初の区切り (break) 文字を指すポインタを返すためです。
例
#include <iostream> #include <cstring> #include <iomanip> 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