std::strpbrk
來自 cppreference.com
在標頭檔案 <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
|