The following is a simple C++ sample program, which can realize this function:
# include & ltiostream & gt
# include & ltcctype & gt// Header file containing character processing function.
int main() {
Std:: string input;
//Prompt the user for a string.
STD::cout & lt; & lt Please enter a string: ";
Std::getline(std::cin, input);
//Traverse the string and convert uppercase and lowercase letters.
for(char & amp; C: input) {
if (std::isupper(c)) {
c = STD::to lower(c); //If it is uppercase, it will be converted to lowercase.
} else if (std::islower(c)) {
c = STD::toupper(c); //If it is lowercase, convert it to uppercase.
}
}
//Output the converted string.
STD::cout & lt; & lt "Converted string:"
Returns 0;
}
————————
This program first prompts the user to enter a string, and then traverses each character in the string. For each character, it uses the std::isupper function to check whether it is an uppercase letter, and if it is, it uses the std::tolower function to convert it into lowercase letters. If the character is lowercase, it uses the std::toupper function to convert it to uppercase. Finally, the program outputs the converted string.
You can copy the above code to the C++ compiler and enter a string for testing. This program demonstrates how to handle case conversion in strings.