Sunday, 31 January 2016

Cpp Program to find length of a string using strlen function


This is a Cpp Program to find the length of a String.
Here we use string function strlen() to find the length of a string.
All the string functions are present in the header string.h




Download Code

PROGRAM :

#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    char name[40];
    cout << "Enter any name(String) : \t";
    cin.get(name , 40);
    cout << "\nThe length of the string you entered is : \t" << strlen(name) << endl;
    return 0;
}

OUTPUT : 

Cpp Program - Length of a string