#include <iostream>
#include <string> // Include the string header

int main() {
    // Creating std::string objects
    std::string str1 = "Hello, ";
    std::string str2 = "world!";
    
    // Concatenating strings
    std::string combined = str1 + str2; // "Hello, world!"
    
    // Getting the length of a string
    std::cout << "Length of combined string: " << combined.length() << std::endl;
    
    // Accessing characters in a string
    char firstChar = combined[0]; // 'H'
    
    // Appending to a string
    combined.append(" How are you?"); // "Hello, world! How are you?"
    
    // Finding substrings
    size_t found = combined.find("world"); // found = 7 (position of "world")
    
    // Substring extraction
    std::string sub = combined.substr(7, 5); // "world"
    
    // Replacing a substring
    combined.replace(7, 5, "C++"); // "Hello, C++! How are you?"
    
    // Removing characters from a string
    combined.erase(13); // "Hello, C++!"
    
    // Checking if a string is empty
    bool isEmpty = combined.empty(); // false
    
    // Iterating through characters in a string
    for (char c : combined) {
        std::cout << c << " ";
    }
    std::cout << std::endl;
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: