codescracker


c++

C++ Program to Find Length of String



« Previous Program Next Program »


Find String Length in C++

To find the length of the string in C++ programming, you have to ask to the user to enter the string and then find the length the that string using function strlen() of string.h library and display the length value of the string on the output screen as shown here in the following program.

C++ Programming Code to Find Length of String

Following C++ program ask to the user to enter a string to find the length of that string using strlen() function, then display the result on the screen:

/* C++ Program - Find Length of String */
		
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{
	clrscr();
	char str[20], len;
	cout<<"Enter a string : ";
	gets(str);
	len=strlen(str);
	cout<<"Length of the string is "<<len;
	getch();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program find length of string

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test