Using strspn to get the length of the initial part of the string in for substring - C++ Data Type

C++ examples for Data Type:char array

Description

Using strspn to get the length of the initial part of the string in for substring

Demo Code

#include <iostream> 
#include <cstring> // strspn prototype 
using namespace std; 

int main() //from  w  ww.j ava 2  s .  c  o  m
{ 
    const char *string1 = "The value is 3.14159"; 
    const char *string2 = "is"; 

    cout << "string1 = " << string1 << "\nstring2 = " << string2 
       << "\n\nThe length of the initial segment of string1\n" 
       << "containing only characters from string2 = " 
       << strspn( string1, string2 ) << endl; 
    return 0;
}

Result


Related Tutorials