Avatar ·

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

Hello! I recently started learning C++ and encountered the problem of choosing between std::string and std::wstring. Both types seem to be designed for working with text, but I don't understand the difference and when to use which. Here's a simple example: I'm writing a program that should work with Russian characters: ```cpp #include #include int main() { std::string str = "Привет, мир!"; std::wstring wstr = L"Привет, мир!"; std::cout << "string length: " << str.length() << std::endl; std::wcout << L"wstring length: " << wstr.length() << std::endl; // Trying to output a character by index std::cout << "First character of string: " << str[0] << std::endl; std::wcout << L"First character of wstring: " << wstr[0] << std::endl; } ``` The output confuses me