Home >Backend Development >C++ >How Can I Display UTF-8 Text Correctly in My C Console Application on Windows?
Displaying UTF-8 Text in C Console Applications on Windows
In a C console application compiled using Visual Studio 2008 on Windows, it can be challenging to correctly print UTF-8 encoded characters. To overcome this issue, follow these steps:
Configure Character Encoding:
Set Console Output Code Page:
Print UTF-8 Characters:
You can now use printf or wprintf to print UTF-8 characters. For example, the following code would print a mix of English, Greek, Spanish, Russian, and ASCII characters:
#include <cstdio> #include <windows.h> int main() { SetConsoleOutputCP(65001); printf("Testing unicode -- English -- Ελληνικά -- Español -- Русский. aäbcdefghijklmnoöpqrsßtuüvwxyz\n"); return 0; }
Additional Tips:
The above is the detailed content of How Can I Display UTF-8 Text Correctly in My C Console Application on Windows?. For more information, please follow other related articles on the PHP Chinese website!