#include#include using namespace std; int main() { string myString = "Hello World"; int length = myString.length(); cout << "Length of string is " << length << endl; return 0; }
#include#include using namespace std; int main() { string myString = "C++ String Length"; int length = myString.length(); for(int i=0; i
In this example, we have extracted each character of the string using a for loop and printed it on the console. The output of the program is:C + + S t r i n g L e n g t hHere, we can see that loop has run 17 times which is same as the number of characters in the string. Both of the above examples use the standard C++ library and hence, no separate package or library is required.