首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::strpbrk

Defined in header <cstring>

const char* strpbrk( const char* dest, const char* breakset );

char* strpbrk( char* dest, const char* breakset );

扫描以空结尾的字节字符串。dest指向的以空结尾的字节字符串中的任何字符。breakset,并返回指向该字符的指针。

参数

dest

-

pointer to the null-terminated byte string to be analyzed

breakset

-

pointer to the null-terminated byte string that contains the characters to search for

返回值

中的第一个字符的指针。dest,这也是在breakset,如果不存在这样的字符,则为空指针。

注记

该名称表示“字符串指针中断”,因为它返回指向分隔符%28中的第一个“中断”%29字符的指针。

二次

代码语言:javascript
复制
#include <iostream>
#include <cstring>
 
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 << 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";
}

二次

产出:

二次

代码语言:javascript
复制
world, friend of mine!
, friend of mine!
 of mine!
 mine!
!
There are 5 words

二次

另见

strcspn

returns the length of the maximum initial segment that consists of only the characters not found in another byte string (function)

strtok

finds the next token in a byte string (function)

strchr

finds the first occurrence of a character (function)

c strpbrk文档

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券