C++ String length() function
Example
Get the length of a string:
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.length();
Try it Yourself »
Definition and Usage
The length() function returns the length of a string.
Note: You can also use the size() function to get the length of a string.
This is just an alias of length() - they behave the same.
Syntax
string.length();
Parameters
None.
Technical Details
| Returns: | The number of characters in a string. |
|---|
Related Pages
Read more about strings in our String Tutorial.