命名空间
变体
操作

std::strpbrk

来自 cppreference.cn
< cpp‎ | string‎ | byte
在头文件 <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