C++String Length
String Length
To get the length of a string, use thelength() function:
Example
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << txt.length();
Try it Yourself »cout << "The length of the txt string is: " << txt.length();
Tip: You might see some C++ programs that use thesize() function to get the length of a string. This is just an alias oflength(). It is completely up to you if you want to uselength() orsize():
Example
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << txt.size();
Try it Yourself »cout << "The length of the txt string is: " << txt.size();

