名前空間
変種
操作

std::strpbrk

提供: cppreference.com
< cpp‎ | string‎ | byte
ヘッダ <cstring> で定義
const char* strpbrk( const char* dest, const char* breakset );
      char* strpbrk(       char* dest, const char* breakset );

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

[編集] 関連項目

別のバイト文字列に含まれない文字のみで構成される最も長い先頭部分の長さを返します
(関数) [edit]
バイト文字列中の次のトークンを探します
(関数) [edit]
文字が現れる最初の位置を探します
(関数) [edit]