String Length – length() or size()
We can find the length of the string (number of characters) using either length() or size() function of the std::string class.
Syntax
string_object.size() or string_object.length()
Parameters
- This function does not take any parameter.
Return Value
- This function returns the number of characters in the string object.
Example
std::string text = "w3wiki"; int length = text.length(); //or int length = text.size();
It will return the length of the string text which is 13.
String Functions In C++
A string is referred to as an array of characters. In C++, a stream/sequence of characters is stored in a char array. C++ includes the std::string class that is used to represent strings. It is one of the most fundamental datatypes in C++ and it comes with a huge set of inbuilt functions. In this article, will look at the functions of string computations.
Contact Us