A string in C++ is used to store text. This kind of variable contains a collection of characters that are enclosed by double quotes " ".
The length() function is simply used to get the length of a given string.
string.length()
The length function takes no parameters.
The length() function returns the length of a string.
#include <iostream>#include <string>using namespace std;int main() {//creating a string variablestring name = "Theophilus";// using the length() functioncout << "The length of the string is: " << name.length();return 0;}
length() function and displayed the result.