DEV Community

Cover image for Inbuilt Functions in C++ for Strings 🐱‍👤
Mayank Kumar
Mayank Kumar

Posted on

Inbuilt Functions in C++ for Strings 🐱‍👤

So in this blog post I will be talking about some of the few inbuilt functions in CPP in string (C++)

The function in C++ language is also known as procedure or subroutine in other programming languages.

To perform any task, we can create function. A function can be called many times. It provides modularity and code reusability.

As we all know C++ is a language that has a rich and vast library, some of which are :-

1) Length Function:

Here with the use of this function we can find out the length of a particular array !!

image

Syntax: strlen(str);

Here in the following image the strlen is the main function that we are using to find out the length of the particular string.

2) Compare Function:

Here with the use of this function we can compare the lengths of two different arrays !!

image

Syntax: strncmp(str1, str2);

Here in the following image the strcmp is the main function that we are using to compare any two arrays, it takes 2 parameters and compare them if the comparison is equal to 0 then the strings are equal other wise they are not equal.

3) String Copy Function:

Here with the use of this function we can copy one arrays into another array !!

image

Syntax: strcpy(destination_str, source_str);

Here in the following image the strcpy is the main function that we are using to copy the data of one element into another array, it takes 2 parameters and copy the data of the later parameter in the first array.

4) String n Copy Function:

Here with the use of this function we can copy some elements of one arrays into another array !!

image

Syntax: strncpy(destination_str, source_str);

Here in the following image the strncpy is the main function that we are using to copy some elements of an array into another array, it takes 2 parameters and copy the data of the later parameter in the first array.

5) String Concatenate Function:

Here with the use of this function we can concatenate both of the arrays !!

image

Syntax: strcat(str1, str2);

Here in the following image the strcat is the main function that we are using to concatenate both of the arrays.

----------------------------------x-------------------------------

Enough for today, now its time for some meme 😎

image

Happy Coding 🚀

Top comments (0)