C++ Program to find length of string using size() function


In this program, You will learn how to find length of string using size() function in C++.


int len = str.size();


Example: How to find length of string using size() function in C++

Run it Now
#include<iostream>
using namespace std;

int main() {

    int len;
    string str;
    cout << "Enter a String :";
    getline(cin, str);

    len = str.size();
    cout << "\nThe Length of String is :" << len;

    return 0;
}

Output:

Enter a string :Learn C++
The Length of string :9