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 the length of string using size() function in C++.

#include<iostream>
using namespace std;

int main() {

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

    len = str.size();
    cout << "Length of string is:" << len;

    return 0;
}

Output:

Enter a string:Xiith.com
Length of string is:9