Avatar ·

std::wstring vs std::string: when to use Unicode and when ASCII in C++?

Hi everyone! I'm a beginner C++ developer, and I'm constantly confused by the difference between std::wstring and std::string. I've read that std::string is for "regular" strings, and std::wstring is for Unicode. But in practice, I run into many problems.\n\nHere's an example: I'm writing a program that reads file names from a folder. Some files contain Cyrillic characters, for example "отчет.docx". Using std::string:\n\n```cpp\nstd::string filename = "отчет.docx";\nstd::ifstream file(filename);\n```\n\nAnd the file doesn't open! If I use std::wstring and wifstream, everything works:\n\n```cpp\nstd::wstring filename = L"отчет.docx";\nstd::wifstream file(filename);\n```\n\nBut then new problems arise: I can't pass wstring to functions that expect std::string (for example, in old libraries), and when outputting to co