#include#include using namespace std; int main() { string str = "Hello"; // Resizing to a larger size str.resize(10); cout << "New string size: " << str.size() << endl; cout << "New string content: " << str << endl; // Resizing to a smaller size str.resize(3); cout << "New string size: " << str.size() << endl; cout << "New string content: " << str << endl; return 0; }
New string size: 10 New string content: Hello New string size: 3 New string content: Hel
#include#include using namespace std; int main() { string str = "ABC"; // Resizing to a larger size str.resize(5, 'X'); cout << "New string size: " << str.size() << endl; cout << "New string content: " << str << endl; // Resizing to a smaller size str.resize(2); cout << "New string size: " << str.size() << endl; cout << "New string content: " << str << endl; return 0; }
New string size: 5 New string content: ABCXX New string size: 2 New string content: ABThis function is part of the C++ Standard Library.