Avatar ·

How to convert a std::string to lowercase in C++?

Hello, colleagues!\n\nI'm new to C++ (previously wrote in Python) and encountered a seemingly simple task: I need to convert all characters in a std::string object to lowercase. In Python, I just write "HELLO".lower() and it's done. But in C++, I'm stuck.\n\nHere's my code that doesn't work:\n\n```cpp\n#include \n#include \n\nint main() {\n std::string text = "HELLO WORLD!";\n std::string lower_text = std::tolower(text); // Error!\n std::cout << lower_text << std::endl;\n return 0;\n}\n```\n\nThe compiler gives an error: `cannot convert 'std::string' to 'int' for argument '1' to 'int tolower(int)'`. I understand that `std::tolower` only works with individual characters (of type `int`), not with the entire string.\n\nI tried writing a loop manually:\n\n```cpp\nfor (si