std::strpbrk(3)
π¦ std::strpbrk(3) π¦
okay so bestie, welcome to the <std::strpbrk(3)> page from the C++ Standard Libary β and the manual name is literally std::strpbrk, no cap. this is the cute little string-pointer-break situation and we're gonna get into it π
π NAME π
std::strpbrk β std::strpbrk.
β¨ Synopsis β¨
Defined in header <cstring>
const char* strpbrk( const char* dest, const char* breakset );
char* strpbrk( char* dest, const char* breakset );
It scans the null-terminated byte string pointed to by dest for any character from the null-terminated byte string pointed to by breakset, and returns a pointer to that character. that's the vibe, lowkey iconic β¨
π Parameters π
destβ pointer to the null-terminated byte string to be analyzedbreaksetβ pointer to the null-terminated byte string that contains the characters to search for
π₯ Return value π₯
Pointer to the first character in dest, that is also in breakset, or null pointer if no such character exists. fr fr, if there's no match you get the null pointer, not a fake one π
π§ Notes π§
The name stands for "string pointer break", because it returns a pointer to the first of the separator ("break") characters. iykyk π§
π Example π
// Run this code
#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";
}
π Output π
" world, friend of mine!"
", friend of mine!"
" of mine!"
" mine!"
"!"
There are 5 words
π See also π
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)wcspbrkβ finds the first location of any wide character in one wide string, in another wide string (function)- C documentation for
strpbrk
π«Ά source: http://cppreference.com Β· version/date: 2024.06.10 Β· page: std::strpbrk(3) β that's the tea, bestie π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms