string class in c++

#include <iostream>
#include <string>

int main() {
    // Declaration of string variables
    std::string str1;
    std::string str2 = "Hello, World!";
    std::string str3(5, 'A');  // Initializes with five 'A' characters

    // String input and output
    std::cout << "Enter a string: ";
    std::cin >> str1;
    std::cout << "You entered: " << str1 << std::endl;

    // String concatenation
    std::string result = str2 + " " + str3;

    // String length
    std::cout << "Length of str2: " << str2.length() << std::endl;

    // String comparison
    if (str1 == str2)
        std::cout << "str1 is equal to str2" << std::endl;
    else
        std::cout << "str1 is not equal to str2" << std::endl;

    // Accessing characters in a string
    char firstChar = str2[0];
    char lastChar = str2[str2.length() - 1];

    // Substring extraction
    std::string subStr = str2.substr(0, 5);  // Retrieves the first 5 characters

    // Finding a substring
    size_t pos = str2.find("World");
    if (pos != std::string::npos)
        std::cout << "Substring found at position " << pos << std::endl;
    else
        std::cout << "Substring not found" << std::endl;

    return 0;
}