Using strcspn to get the length of the initial part of the string that does not contain any characters from another string. - C++ Data Type

C++ examples for Data Type:char array

Description

Using strcspn to get the length of the initial part of the string that does not contain any characters from another string.

Demo Code

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

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

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

Result


Related Tutorials