I wrote two versions of a little program in C++ with MSVC on Windows 11:
First one:
#include <iostream>
#include <Windows.h>
int main()
{
SetConsoleOutputCP(CP_UTF8);
std::cout << u8"ä ü ö \n";
}
That did not work. But the following one did work:
#include <iostream>
#include <Windows.h>
int main()
{
SetConsoleOutputCP(CP_UTF8);
std::cout << "ä ü ö \n";
}
The difference was the u8 in front of the string literal.
Why did it not work? With "did not work" I mean, that the output on the console was not "ä ü ö" but other symbols.
lang-cpp
std::cout << u8"ä ü ö \n";? That's surprising. Must be an MSVC extension..cppfile itself saved as? If you do not specify/utf-8during compiling then DO NOT save the file as UTF-8. But if your file IS saved as UTF-8 then you need/utf-8. Read up about your compiler's Source Charset and Execution Charset options. They affect howcharstrings are interpreted at compile-time and run-time, respectively. Also, your/Ddefines for Unicode only affectTCHAR-based strings+macros, none of which you are using in your example.std::ostream& operator<<(std::ostream&, const char8_t*)overload required. It's been deleted since C++20 but I see that OP mentions using C++14 in the comments, so that clears that up. :-)