std::string str = "Hello, world!"; str.truncate(5); // str is now "Hello"
std::string input; std::getline(std::cin, input); // User inputs "This is a really long string" input.truncate(10); // input is now "This is a"
std::string title = "The Great Gatsby"; std::string author = "F. Scott Fitzgerald"; std::string displayString = title + " by " + author; displayString.truncate(20); // displayString is now "The Great Gatsby by"The `truncate` function is part of the C++ Standard Library, so no additional library is required.