#include#include int main() { std::string hello = "Hello World!"; std::cout << "The length of the string is: " << hello.size() << std::endl; return 0; }
#includeThis example prompts the user to enter their name, reads the input using `getline()` function and stores it in the `name` string object. Then, we use the `size()` method to get the length of the string and display it to the user. These examples use the C++ Standard Library.#include int main() { std::string name; std::cout << "Enter your name: "; getline(std::cin, name); std::cout << "Your name has " << name.size() << " characters." << std::endl; return 0; }