#include#include using namespace std; int main() { string str1 = "Hello"; string str2; str2.assign(str1); cout << str2 << endl; // Output: Hello return 0; }
#include#include using namespace std; int main() { const char arr[] = "World"; string str; str.assign(arr); cout << str << endl; // Output: World return 0; }
#includePackage Library: Standard C++ Library#include using namespace std; int main() { string str1 = "Testing"; string str2; str2.assign(str1, 0, 4); // Starting from index 0, take 4 characters cout << str2 << endl; // Output: Test return 0; }