C++ String Length: Quick Guide

To output the length of a string in C++, you can use the size() or length() method of the std::string class to get the length of the string, and then output it. Here is a simple example code:

#include <iostream>
#include <string>

int main() {
    std::string str = "Hello, World!";
    
    std::cout << "Length of the string is: " << str.size() << std::endl;
    
    return 0;
}

In the example above, the method str.size() is used to retrieve the length of the string str and output it to the console. If you want to use the length() method, you can replace str.length() with str.size().

Running the above code will result in:

Length of the string is: 13
bannerAds