#include#include int main() { std::string str = "Hello World!"; std::cout << "Original string: " << str << "\n"; str.resize(5); std::cout << "Resized string: " << str << "\n"; return 0; }
Original string: Hello World! Resized string: Hello
#include#include int main() { std::string str = "Hello"; std::cout << "Original string: " << str << "\n"; str.resize(10, 'x'); std::cout << "Resized string: " << str << "\n"; return 0; }
Original string: Hello Resized string: HelloxxxxxIn this example, the original string has a length of 5. After calling the `resize` function with a value of 10 and a fill character of 'x', the string is resized to "Helloxxxxx". Package library: Standard Template Library (STL)