Algorithm


1. Input: Receive a C-style string (character array) as input.

2. Initialization: Initialize a variable length to 0 to store the length of the string.

3. Loop: Use a loop to iterate through the characters of the string.
    While the current character is not the null character ('\0'):
     Increment the length variable.
       Move to the next character in the string.

4. Output: Return the final value of the length variable as the length of the string.

Code Examples

#1 Code Example- C++ programin Length of String Object

Code - C++ Programming

#include <iostream>
using namespace std;

int main() {
    string str = "C++ Programming";

    // you can also use str.length()
    cout << "String Length = " << str.size();

    return 0;
}
Copy The Code & Try With Live Editor

Output

x
+
cmd
String Length = 15
Advertisements

Demonstration


C++ Programing Example to Find the Length of a String-DevsEnv