C++ strspn() Function

Last Updated:

C++ strspn()

The strspn() function finds up to what length two strings are identical.

This function is defined in <cstring> header file.


C++ Compiler
#include <iostream> #include <cstring> using namespace std; int main() { char str1[] = "wikimass is awesome"; char str2[] = "wikipedia is great"; long len = strspn(str1, str2); cout << "Length of initial segment matching: " << len; return 0; }


size_t strspn(const char *str1, const char *str2)

Parameter Values

str1 Required Specifies the string 1
str2 Required Specifies the string 2

Return Value

Number Returns the position of the string from where the source array does not matches with the target one.

Share this Page

Meet the Author