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