在线文档教程
C++
字符串 | Strings

std::strpbrk

STD:strpbrk

Defined in header
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字符的指针。

二次

#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"; }

二次

产出:

二次

world, friend of mine! , friend of mine! of mine! mine! ! There are 5 words

二次

另见

strcspnreturns the length of the maximum initial segment that consists of only the characters not found in another byte string (function)
strtokfinds the next token in a byte string (function)
strchrfinds the first occurrence of a character (function)

c strpbrk文档

© cppreference.com

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

http://en.cppreference.com/w/cpp/string/字节/strpbrk