C++ strpbrk() Function

You are Here:

C++ strpbrk()

The strpbrk() function searches the first occurrence of the character in a given string and then it displays the string starting from that character.

This function is defined in <cstring> header file.

Example

C++ Compiler
#include <iostream> #include <cstring> using namespace std; int main() { char str1[] = "wikimass.com"; char str2[] = "msi"; char *ptr; ptr = strpbrk(str1, str2); if(ptr) { cout << "First matching character: " << *ptr; cout << "\nNew String: " << ptr; } else { cout << "Character not found"; } return 0; }

Output

First matching character: i New String: ikimass.com

Syntax

char *strpbrk(const char *str1, const char *str2)

Parameter Values

ValueTypeExplanation
str1RequiredSpecifies an actual string
str2RequiredSpecifies a string of characters to be searched in str1.

Return Value

ValueExplanation
AddressReturns the pointer position to the first occurrence of the character (str2) in the string (str1).
NULLIf no occurrence of the character (str2) in the string (str1).

Reminder

Hi Developers, we almost covered 90% of String functions and Interview Question on C++ with examples for quick and easy learning.

We are working to cover every Single Concept in C++.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author