Namespaces
Variants
Views
Actions

std::strpbrk

From cppreference.com
< cpp‎ | string‎ | byte
Revision as of 16:07, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <cstring>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td class="t-dcl-nopad">
const char* strpbrk( const char* dest, const char* str );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td class="t-dcl-nopad">
      char* strpbrk(       char* dest, const char* str );
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

Finds the first character in byte string pointed to by dest, that is also in byte string pointed to by str.

Contents

Parameters

dest - pointer to the null-terminated byte string to be analyzed
str - 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 str, or NULL if no such character exists.

Example

#include <cstdio>
#include <cstring>
 
int main() 
{
    char* input = "hello world friend of mine";
    char* space = " ";
    char* pos = input;
    int word_counter = 0;
 
    do {
        pos = std::strpbrk(pos, space);
        word_counter++;
        pos ? pos++ : pos;
        std::printf("%d\n", word_counter);
    } while (pos != NULL);
};

Output:

1
2
3
4
5

See also

Template:cpp/string/byte/dcl list strcspnTemplate:cpp/string/byte/dcl list strchr
C documentation for strpbrk