A std::string can change after it is created. You can replace one character using its index or add more text at the end.
#include <iostream>
#include <string>
int main() {
std::string label = "hall";
label[0] = 'H';
label += " B";
std::cout << label << '\n';
return 0;
}
The indexed assignment replaces the first character without changing the string's length. The right-hand side is 'H', a single char, not "H", a string literal. This is safe because the supplied string has a character at index 0. For variable input, check that the index is less than size() before writing.
+= appends text to the existing string. The old content remains, followed by the suffix, so the example produces Hall B. It is equivalent here to assigning label = label + " B". The space belongs to the suffix; it is not added for you.
String operations do not all have the same effect. substr creates a separate result, while indexed assignment and += change the string they operate on. If you call substr without storing or displaying its result, the original string remains unchanged.
Leave the initial strings in place and add the changes at their TODO comments. The first edit should replace a character in heading; the second should append text to status. Each output statement follows its editing area, so it will display the changed value. An update written after that output would happen too late to appear on its line.
heading's first character to 'G'. Expect Heading: Garden club.+= to append " confirmed" to status. Expect Status: Booking confirmed.Edit main.cpp, press Run to inspect the Console, then Submit to check your work.