replace a char in string c++ at a specific index

#include <iostream>
#include <string>
using namespace std;

int main() {
    string str = "Hello, world!";
    int index = 7;
    char newChar = 'W';

    str[index] = newChar;

    cout << str << endl;

    return 0;
}