Avatar ·

How to work with strings in C++?

Hello everyone! I started learning C++ and encountered a problem when working with strings. I'm trying to write a simple program that reads the user's name and then outputs a greeting with that name converted to uppercase. But the code doesn't work as I expected.

Here's what I tried:

#include <iostream>\n#include <string>\n#include <cctype>\n\nint main() {\n    std::string name;\n    std::cout << "Enter name: ";\n    std::cin >> name;\n    \n    for (char c : name) {\n        c = std::toupper(c);\n    }\n    \n    std::cout << "Hello, " << name << "!" << std::endl;\n    return 0;\n}

The problem is that the name is output in its original case, although I expected it to be in uppercase. It seems that th