C++ Program to Find the Length of a String

bookmark

#include<iostream>
#include<string.h>
using namespace std;
int main ()
{
    char str[50];
    int len;
    cout << "Enter an array or string : ";
    gets(str);
    len = strlen(str);
    cout << "Length of the string is : " << len;
    return 0;
}

 

Output:

Enter an array or string : 1020304050
Length of the string is : 10