The word "strlen" is the short of String length. The strlen() function is used to find out the length of a string. This function counts the total number of characters in the string including spaces. But, the null character ('\0') is not counted.
Syntax of strlen() Function
In C++, the general syntax of strlen() function is as follows:Where:
var = strlen (string);
string | It represents the given string whose length is to be found. It may be a string variable or constant. |
var | It indicates the integer variable into which the length of the string is to be stored. |
Example of strlen() Function
The following source code of the C++ program inputs a string variable and finds its length using strlen() function.Output:
#include
#include
#include
main()
{
char str[200];
cout
gets(str);
cout
return 0;
}
Enter a string: C++ Tutorials
Length of string is: 13