#include#include using namespace std; int main() { string str1 = "Hello"; string str2 = "World"; string str3 = str1 + " " + str2; cout << "Length of str3: " << str3.length() << endl; cout << "First character of str1: " << str1.front() << endl; cout << "Last character of str2: " << str2.back() << endl; return 0; }
#includeIn this example, we declare two std string data variables, `str1` and `str2`. We then use the `compare()` function to compare `str1` and `str2` and print out whether they are the same or different. We then use the `replace()` function to replace a portion of `str2` with a new string (in this case, "berry"). We then print out the modified `str2`. In conclusion, the CPP std string data library is a powerful tool for handling text and string data in C++. It provides many useful features and functions for manipulating and working with strings.#include using namespace std; int main() { string str1 = "apple"; string str2 = "orange"; if (str1.compare(str2) == 0) { cout << "The strings are the same." << endl; } else { cout << "The strings are different." << endl; } str2.replace(2, 4, "berry"); cout << "New string: " << str2 << endl; return 0; }