How to find the length of a string in c++ – C++ Program to Find the Length of a String

How to find the length of a string in c++: In the previous article, we have discussed C++ Program to Check whether a string is Palindrome or Not. In this article, we will see C++ Program to Find the Length of a String.

C++ Program to Find the Length of a String

  • How to find length of a string without using any standard library functions in C++.
  • C++ program to calculate string length using while loop.

C++ program to find the length of a string

C++ program to find the length of a string

#include <iostream>
 
using namespace std;
  
int main(){
    char str[1000];
    int length = 0;
    cout << "Enter a string\n";
    cin.getline(str, 1000);
 
    while(str[length] != '\0'){
     length++;
    }
      
    cout << "Length of String is : " << length << endl;
      
    return 0;
}

Output

Enter a string
techcrashcourse
Length of String is : 15

The list of C++ Example Programs include swapping number, addition, multiplication of two numbers, factorial of a number and many more. Interested people can get the cpp code to get a clear idea on the programming language.