std::strpbrk
来自 cppreference.cn
定义于头文件 <cstring> |
||
const char* strpbrk( const char* dest, const char* breakset ); |
||
char* strpbrk( char* dest, const char* breakset ); |
||
扫描由 dest 指向的空终止字节字符串,查找由 breakset 指向的空终止字节字符串中的任何字符,并返回指向该字符的指针。
内容 |
[edit] 参数
dest | - | 指向要分析的空终止字节字符串的指针 |
breakset | - | 指向包含要搜索的字符的空终止字节字符串的指针 |
[edit] 返回值
指向 dest 中第一个同时也在 breakset 中的字符的指针;如果不存在这样的字符,则返回空指针。
[edit] 注释
名称代表 “string pointer break”(字符串指针中断),因为它返回指向第一个分隔符(“break”)字符的指针。
[edit] 示例
运行此代码
#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
[edit] 参见
返回由不包含在另一个字节字符串中的字符组成的最大初始段的长度 (仅由不包含在另一个字节字符串中的字符组成) (函数) | |
在字节字符串中查找下一个标记 (函数) | |
查找字符的首次出现 (函数) | |
在一个宽字符串中查找任何宽字符在另一个宽字符串中的首次出现位置 (函数) | |
C 文档 for strpbrk
|