C++ String size
This function is employed to retrieve the byte length of a string. It specifies the precise count of bytes that represent the string's content, which may differ from its capacity.
Syntax
To determine the length of a string object named 'str', you can use the following syntax:
str.size()
Parameters
This function does not contain any parameter.
Return Value
This function calculates and returns the total count of characters existing within the string entity.
Example 1
#include<iostream>
using namespace std;
int main()
{
string str ="Welcome to the javacpptutorial tutorial";
int size = str.size();
cout << "length of the string is :" <<size;
return 0;
}
Output:
length of the string is : 34
In this instance, the variable str represents a string object with the content "Welcome to the javacpptutorial tutorial". The size function is employed to determine the length of the string.